所有发布的与 mysql 库相关的问题都使用标准 gcc 编译器。但是,我需要编译在 beaglebone black 设备上运行的项目。因此,我使用arm-linux-gnueabihf-gcc
而不是gcc
。
这是我的环境:
- Ubuntu - 32 位
- 使用 eclipse luna c++
- mysql 在 beaglebone 上运行良好。现在,我正在使用 C++ 编写代码来访问 mysql。
请帮助修复我的错误。谢谢,使用标准 gcc 进行编译工作正常,所以这意味着我已经安装了
apt-get install libmysqlclient-dev
apt-get install libmysqlcppconn-dev
apt-get install mysql-client
apt-get install mysql-server
因此,这是我编译后得到的结果:
12:38:15 **** Incremental Build of configuration Debug for project arm2 ****
make all
Building file: ../src/arm2.cpp
Invoking: GCC C++ Compiler
arm-linux-gnueabihf-g++ -I/usr/arm-linux-gnueabihf/include/mysql -I/usr/arm-linux-gnueabihf/include/mysql/cppconn -I/usr/arm-linux-gnueabihf/include/c++/4.8.2 -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/arm2.d" -MT"src/arm2.d" -o "src/arm2.o" "../src/arm2.cpp"
../src/arm2.cpp: In function ‘int main()’:
../src/arm2.cpp:32:10: warning: variable ‘driver’ set but not used [-Wunused-but-set-variable]
Driver *driver;
^
Finished building: ../src/arm2.cpp
Building target: arm2
Invoking: GCC C++ Linker
arm-linux-gnueabihf-g++ -L/usr/arm-linux-gnueabihf/lib -L/usr/arm-linux-gnueabihf/libsf -L/usr/lib/mysql -L/usr/lib -o "arm2" ./src/arm2.o -lmysqlcppconn
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/bin/ld: skipping incompatible /usr/arm-linux-gnueabihf/lib/libmysqlcppconn.so when searching for -lmysqlcppconn
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/bin/ld: skipping incompatible /usr/lib/libmysqlcppconn.so when searching for -lmysqlcppconn
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/bin/ld: skipping incompatible /usr/lib/libmysqlcppconn.a when searching for -lmysqlcppconn
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/bin/ld: skipping incompatible /usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/../lib/libmysqlcppconn.so when searching for -lmysqlcppconn
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/bin/ld: skipping incompatible /usr/lib/../lib/libmysqlcppconn.so when searching for -lmysqlcppconn
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/bin/ld: skipping incompatible /usr/lib/../lib/libmysqlcppconn.a when searching for -lmysqlcppconn
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/bin/ld: skipping incompatible /usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/lib/libmysqlcppconn.so when searching for -lmysqlcppconn
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/bin/ld: skipping incompatible //usr/lib/libmysqlcppconn.so when searching for -lmysqlcppconn
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/bin/ld: skipping incompatible //usr/lib/libmysqlcppconn.a when searching for -lmysqlcppconn
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/bin/ld: skipping incompatible /usr/arm-linux-gnueabihf/lib/libmysqlcppconn.so when searching for -lmysqlcppconn
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lmysqlcppconn
collect2: error: ld returned 1 exit status
make: *** [arm2] Error 1
12:38:18 Build Finished (took 2s.451ms)
答案1
您必须首先删除这些选项,因为您的链接器正在尝试在这些路径中查找(显然没有 .so 文件):-L / usr / lib / mysql -L / usr / lib并从您的 BBB 查找并将这些文件复制到您的机器:
libmysqlclient.a
libmysqlclient.so
ld-linux.so.3
ld-linux-armhf.so.3
libmysqlclient.a
libmysqlclient.so
libz.so.1
然后将 -L 这些文件添加到您的链接器选项中。
最后,将这些选项添加到你的链接器:
-L/usr/lib/arm-linux-gnueabihf -L/lib/arm-linux-gnueabihf -lmysqlclient -lpthread -lz -lm -lrt -ldl