我有以下编译时错误我找不到原因:
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
答案 0 :(得分:4)
你很可能错过了&libffysqlcppconn-dev'图书馆。安装后,您不应该看到此错误。
答案 1 :(得分:0)
在更新系统之前,我在源代码中包含了MySQL标题,如下所示:
#include <mysql_connection.h>
现在我必须指定子目录:
#include <driver/mysql_connection.h>
路径设置的方式必须改变......