<bdo id='heEEE'></bdo><ul id='heEEE'></ul>

      <tfoot id='heEEE'></tfoot>
    1. <small id='heEEE'></small><noframes id='heEEE'>

    2. <i id='heEEE'><tr id='heEEE'><dt id='heEEE'><q id='heEEE'><span id='heEEE'><b id='heEEE'><form id='heEEE'><ins id='heEEE'></ins><ul id='heEEE'></ul><sub id='heEEE'></sub></form><legend id='heEEE'></legend><bdo id='heEEE'><pre id='heEEE'><center id='heEEE'></center></pre></bdo></b><th id='heEEE'></th></span></q></dt></tr></i><div id='heEEE'><tfoot id='heEEE'></tfoot><dl id='heEEE'><fieldset id='heEEE'></fieldset></dl></div>

      <legend id='heEEE'><style id='heEEE'><dir id='heEEE'><q id='heEEE'></q></dir></style></legend>
    3. 在 cmakelist.txt 中添加和链接 mysql 库

      时间:2024-04-16
        <tfoot id='ORt3r'></tfoot>
          <bdo id='ORt3r'></bdo><ul id='ORt3r'></ul>

        • <legend id='ORt3r'><style id='ORt3r'><dir id='ORt3r'><q id='ORt3r'></q></dir></style></legend>

            <small id='ORt3r'></small><noframes id='ORt3r'>

                <i id='ORt3r'><tr id='ORt3r'><dt id='ORt3r'><q id='ORt3r'><span id='ORt3r'><b id='ORt3r'><form id='ORt3r'><ins id='ORt3r'></ins><ul id='ORt3r'></ul><sub id='ORt3r'></sub></form><legend id='ORt3r'></legend><bdo id='ORt3r'><pre id='ORt3r'><center id='ORt3r'></center></pre></bdo></b><th id='ORt3r'></th></span></q></dt></tr></i><div id='ORt3r'><tfoot id='ORt3r'></tfoot><dl id='ORt3r'><fieldset id='ORt3r'></fieldset></dl></div>
                  <tbody id='ORt3r'></tbody>

              • 本文介绍了在 cmakelist.txt 中添加和链接 mysql 库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在一个需要使用 MySQL 库的项目中工作.我在过去取得了成功,使用了一个简单的 makefile,我在其中编写了特定的标志.

                I'm working in a project where I need to use MySQL LIBRARIES. I had success in the past, using a simple makefile where I wrote the specific flags.

                CFLAGS+=`mysql_config --cflags`
                LIB+=`mysql_config --libs`
                

                但是...对于我的项目需要使用 cmakelist,我对此有困难.我可以使用以下代码添加 GTK 库:

                However... for my project is required to use a cmakelist and I'm having difficulties with that. I can add GTK libraries with this code:

                find_package(PkgConfig REQUIRED)
                pkg_check_modules(GTK REQUIRED gtk+-3.0)
                
                include_directories(${GTK_INCLUDE_DIRS})
                link_directories(${GTK_LIBRARY_DIRS})
                target_link_libraries( cgm ${GTK_LIBRARIES} )
                

                但是对于 MySQL,我遇到了麻烦.我尝试了很多事情都没有成功,但我相信这类似于 GTK 示例.谁能帮我解决这个问题?

                but for MySQL I'm in trouble. I tried many things unsuccessfully, but I believe that is similar to the GTK example. Can anyone help me with this problem?

                推荐答案

                最简单的方法是找到(例如使用谷歌)FindMySQL.cmake 脚本,它对你有用.这个脚本可以像往常一样与 find_package 命令一起使用:

                The simplest way could be to find (e.g. with google) FindMySQL.cmake script, which works for you. This script can be used with find_package command as usual:

                list(CMAKE_MODULE_PATH APPEND <directory-where-FindMySQL.cmake-exists>)
                find_package(MySQL REQUIRED)
                
                include_directories(${MYSQL_INCLUDE_DIR})
                target_link_libraries(cgm ${MYSQL_LIB})
                

                (变量名MYSQL_INCLUDE_DIRMYSQL_LIB 的具体脚本可以不同).

                (Names of variables MYSQL_INCLUDE_DIR and MYSQL_LIB can be different for concrete script).

                但是手动链接 MySQL 库并不难,知道计算 CFLAGS 和 LIBS 的方法.

                But it is not difficult to link with MySQL library manually, knowing way for compute CFLAGS and LIBS.

                在配置阶段(执行cmake)程序可以用execute_process,用于为特定目标添加 CFLAGS 和 LIBS 使用 target_compile_options 和 target_link_libraries 相应地:

                During configuration stage(executing of cmake) programs can be run with execute_process, for add CFLAGS and LIBS for specific target use target_compile_options and target_link_libraries correspondingly :

                execute_process(COMMAND mysql_config --cflags
                    OUTPUT_VARIABLE MYSQL_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
                execute_process(COMMAND mysql_config --libs
                    OUTPUT_VARIABLE MYSQL_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
                
                target_compile_options(cgm PUBLIC ${MYSQL_CFLAGS})
                target_link_libraries(cgm ${MYSQL_LIBS})
                

                这篇关于在 cmakelist.txt 中添加和链接 mysql 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:定义外键有什么好处 下一篇:docker 容器启动后运行命令

                相关文章

                  <bdo id='CbHhe'></bdo><ul id='CbHhe'></ul>
              • <tfoot id='CbHhe'></tfoot>
              • <i id='CbHhe'><tr id='CbHhe'><dt id='CbHhe'><q id='CbHhe'><span id='CbHhe'><b id='CbHhe'><form id='CbHhe'><ins id='CbHhe'></ins><ul id='CbHhe'></ul><sub id='CbHhe'></sub></form><legend id='CbHhe'></legend><bdo id='CbHhe'><pre id='CbHhe'><center id='CbHhe'></center></pre></bdo></b><th id='CbHhe'></th></span></q></dt></tr></i><div id='CbHhe'><tfoot id='CbHhe'></tfoot><dl id='CbHhe'><fieldset id='CbHhe'></fieldset></dl></div>

                <small id='CbHhe'></small><noframes id='CbHhe'>

                1. <legend id='CbHhe'><style id='CbHhe'><dir id='CbHhe'><q id='CbHhe'></q></dir></style></legend>