gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 08:06:10 26 4
gpt4 key购买 nike

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

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 得到的 fatal error :

> 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”库。安装后,您应该不会看到此错误。

关于c++ - 使用 MySQL Connector C++ 构建程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18387806/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com