开发者

Error building application using Mysql connector

开发者 https://www.devze.com 2023-03-03 13:37 出处:网络
I have a problem with building a hello world application with MYSQL connector under c++. Here is the build log:

I have a problem with building a hello world application with MYSQL connector under c++. Here is the build log:

"/usr/bin/make" -f nbproject/Makefile-Release.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/c/data/c++/MySqlConnectorHW'
"/usr/bin/make"  -f nbproject/Makefile-Release.mk dist/Release/MinGW-Windows/mysqlconnectorhw.exe
make[2]: Entering directory `/c/data/c++/MySqlConnectorHW'
mkdir -p dist/Release/MinGW-Windows
g++.exe -v -d    -v -L C:\Program Files\MySQL\MySQL Connector C++ 1.1.0\lib\opt\mysqlcppconn.dll -o dist/Release/MinGW-Windows/mysqlconnectorhw build/Release/MinGW-Windows/main.o -L/C/Program\ Files/MySQL/MySQL\ Connector\ C++\ 1.1.0/lib/opt -L/C/boost/libs -L/C/Program\ Files/MySQL/MySQL\ Connector\ C\ 6.0.2/lib/opt 
g++.exe: Files\MySQL\MySQL: No such file or directory
g++.exe: Connector: No such file or directory
g++.exe: C++: No such file or directory
g++.exe: 1.1.0\lib\opt\mysqlcppconn.dll: No such file or directory
Using built-in specs.
COLLECT_GCC=C:\MinGW\bin\g++.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.5.2/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.5.2/configure --enable-languages=c,c++,ada,fortran,objc,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --disable-werror --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.5.2 开发者_如何转开发(GCC) 
make[2]: Leaving directory `/c/data/c++/MySqlConnectorHW'
make[1]: Leaving directory `/c/data/c++/MySqlConnectorHW'
make[2]: *** [dist/Release/MinGW-Windows/mysqlconnectorhw.exe] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 21s)

Can someone help me with this issue? Thanks.


I've only used g++ under Unix, so some of this is based around the example you've given (and may be wrong).

You have several problems. You're getting some weird behaviour from g++ because it is treating this C:\Program Files\MySQL\MySQL Connector C++ 1.1.0\lib\opt\mysqlcppconn.dll as different arguments (seperated by space) C:\Program, Files\MySQL\MySQL, Connector, C++ and 1.1.0\lib\opt\mysqlcppconn.dll. This could be overcome by quoting the string "C:\Program Files\MySQL\MySQL Connector C++ 1.1.0\lib\opt\mysqlcppconn.dll".

However, the -L parameter passed to g++ is used to specify the search paths for libraries, so I wouldn't expect you to specify the name of the dll at this point. I'd expect you to pass -L"C:\Program Files\MySQL\MySQL Connector C++ 1.1.0\lib\opt". Based on your similar -L arguments, it would also appear that it's possible to achieve this by escaping codes in the string,, in which case you end up with: -L/C/Program\ Files/MySQL/MySQL\ Connector\ C++\ 1.1.0/lib/opt, which as it happens you're already passing.

Conclusion:, it seems likely that this: -L C:\Program Files\MySQL\MySQL Connector C++ 1.1.0\lib\opt\mysqlcppconn.dll is really supposed to be specifying a library to link with, not a search path. If this is the case, then you should be using -l, not -L it should simply be: -lmysqlcppconn (at least that's how it would work in Unix, under windows you may need to specify an extension i.e. -lmsqlcppcon.lib).

g++ will then try to resolve missing links by searching in all of the paths specified by -L parameters, to see if they have any libraries matching the supplied -l parameter.

I would suggest opening up the makefile: nbproject/Makefile-Release.mk and having a look to see where this parameter is coming from and update it accordingly.

Looking at the rest of your parameters, it's worth noting that you may have a similar problem when it gets to your output, since it also has a space in it that doesn't appear to be escaped:

-o dist/Release/MinGW-Windows/mysqlconnectorhw build/Release/MinGW-Windows/main.o


Several comments can be found on the internet of how to link the binary version of mysql-connector with your own code: http://dev.mysql.com/doc/refman/5.0/en/building-clients.html

A different route would be to build the source code of mysql-connector-c and mysql-connector-c++. The official version does not support MinGW as a target. However, the following post includes a link to adapted code versions for MinGW: http://forums.mysql.com/read.php?117,425191,425191#msg-425191

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号