数据库
首页 > 数据库> > 使用MySQL Connector C构建程序时出错

使用MySQL Connector C构建程序时出错

作者:互联网

我遇到以下编译时错误,我找不到原因:

fatal error: mysql_connection.h: No such file or directory

我正在使用cmake,这些是CMakeLists.txt文件:

# Top level CMakeLists.txt - MyProg

cmake_minimum_required (VERSION 2.6)
set (PROJECT_NAME "MyProg")

### Out-of-tree directories
set (UTILITIES_DIR "~/utilities")

### Configure header file to pass CMake's settings to the source code
configure_file (
    "Config.h.in"
    "${PROJECT_SOURCE_DIR}/Config.h"
    )

add_subdirectory (src "${CMAKE_CURRENT_BINARY_DIR}/obj")
add_subdirectory (${UTILITIES_DIR} "${CMAKE_CURRENT_BINARY_DIR}/obj/external/utilities")

# Source level CMakeLists.txt - MyProg/src

### MySQL Connector/C++ ###

set (MYSQLCONNECTORCPP_ROOT_DIR "~/3rdParty/mysql-connector-c++-1.1.0")

### Include paths ###

include_directories (${CMAKE_CURRENT_SOURCE_DIR})
include_directories (${UTILITIES_DIR})
include_directories (${MYSQLCONNECTORCPP_ROOT_DIR})
include_directories (/usr/local/include)

link_directories (/usr/local/lib)
link_directories (${MYSQLCONNECTORCPP_ROOT_DIR}/driver)
link_directories (/usr/lib64/mysql/)
link_directories (/usr/lib64/)
link_directories (/usr/local/mysql/lib/)

add_executable (myprog
    entrypoint.cpp
    MyProg.cpp
    MyProg_test.cpp
    ${UTILITIES_DIR}/DBInterface.cpp
    )

target_link_libraries (myprog mysqlcppconn-static mysqlclient)

这是cmake的输出(超出源构建):

> cmake ../MyProg/
-- The C compiler identification is GNU 4.7.1
-- The CXX compiler identification is GNU 4.7.1
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: ~/MyProg_prj/Debug

这是我从make中得到的致命错误:

> make
Scanning dependencies of target myprog
[  8%] Building CXX object obj/CMakeFiles/myprog.dir/entrypoint.cpp.o
In file included from ~/MyProg_prj/MyProg/src/entrypoint.cpp:18:0:
~/utilities/DBInterface.hpp:18:30: fatal error: mysql_connection.h: No such file or directory
compilation terminated.
make[2]: *** [obj/CMakeFiles/myprog.dir/entrypoint.cpp.o] Error 1
make[1]: *** [obj/CMakeFiles/myprog.dir/all] Error 2
make: *** [all] Error 2

mysql_connection.h文件位于CMakeLists.txt文件中指定的目录中.

在我升级Linux之后(在它正常工作之前)发生了此问题,但这不是原因. PATH应该包含所有需要的内容.

谢谢.

平台:Linux(OpenSuse),GCC 4.7.1,cmake,MySQL Connector C 1.1.0

解决方法:

您最有可能缺少“ libmysqlcppconn-dev”库.安装完成后,您应该不会看到此错误.

标签:mysql-connector,compiler-errors,cmake,mysql,c-4
来源: https://codeday.me/bug/20191030/1968416.html