我之前已经多次问过这个问题,但大多数问题都涉及那些不知道添加Project->Properties->C/C++ Build->Settings->GCC C++ Compiler->Include
的包含路径的人。
我正在尝试向Eclipse添加一些与MySQL相关的头文件,并将它们添加到上面的路径中,如this image中所示(列表中的第三个)。构建项目后,no error is raised 表示查找标题时出现问题。
但是在运行应用程序时,会显示"No such File or Directory"错误。但更奇怪的是,在询问open the Declaration时,它会引导我the right file!!
API头文件中还有其他奇怪的错误,例如未定义的引用错误,但我计划一次解决这个问题。我有posted a related question我没有得到任何帮助,所以在任何一种情况下,任何输入都会有所帮助。
编辑:
这些是包含所需文件的构建步骤:
g++ "-IC:\\Program Files\\MySQL\\MySQL Server 5.6\\include" "-IC:\\Program Files\\MySQL\\Connector.C++ 1.1\\include" "-IC:\\MinGW\\include" "-IC:\\boost_1_66_0" -O2 -g -Wall -Wextra -c -fmessage-length=0 -o CDevice.o "..\\CDevice.cpp"
In file included from C:\Program Files\MySQL\Connector.C++ 1.1\include/cppconn/connection.h:33:0,
from C:\Program Files\MySQL\Connector.C++ 1.1\include/cppconn/driver.h:30,
from C:\Program Files\MySQL\Connector.C++ 1.1\include/mysql_driver.h:32,
from ..\CSlaveController.h:25,
from ..\CDevice.h:12,
from ..\CDevice.cpp:8:
g++ "-LC:\\Program Files\\MySQL\\Connector.C++ 1.1\\lib\\opt" "-LC:\\Program Files\\MySQL\\MySQL Server 5.6\\lib" "-LC:\\MinGW\\lib" -o SlaveController.exe CDevice.o CSlaveController.o main.o "C:\\Program Files\\MySQL\\Connector.C++ 1.1\\lib\\opt\\mysqlcppconn-static.lib" "C:\\Program Files\\MySQL\\MySQL Server 5.6\\lib\\libmysql.lib" -lwsock32 -llibmysql -llibmysql -lmysqlclient -lmysqlcppconn -lmysqlcppconn-static
错误是:
fatal error: mysql_driver.h: No such file or directory CSlaveController.h /SlaveController line 25 C/C++ Problem
编辑2:
这是我遇到问题的代码:
sql::Driver *driver;
sql::Connection *connection;
sql::Statement *statement;
sql::PreparedStatement *prepared;
driver = get_driver_instance();
sql::SQLString ip = "127.0.0.1";
sql::SQLString user = "DBServer";
sql::SQLString password = "root";
if(driver !=NULL){
connection = driver->connect("127.0.0.1","DBServer","root"); //CRASH!!!!
}