当前位置: 技术问答>linux和unix
编译问题。myslq++的
来源: 互联网 发布时间:2017-03-03
本文导语: 错误代码: [root@locahost test]# make -f makefile_new g++ -fPIC -I./include/ -g -c test.cpp g++ -fPIC -I./include/ -g -c DbManager.cpp g++ -shared -fPIC -I./include/ -o libdbmanager.so test.o DbManager.o DbManager.o:(.data.rel.local+0x14): multiple defini...
错误代码:
[root@locahost test]# make -f makefile_new
g++ -fPIC -I./include/ -g -c test.cpp
g++ -fPIC -I./include/ -g -c DbManager.cpp
g++ -shared -fPIC -I./include/ -o libdbmanager.so test.o DbManager.o
DbManager.o:(.data.rel.local+0x14): multiple definition of `db_user::table_'
test.o:(.data.rel.local+0x14): first defined here
DbManager.o:(.data.rel.local+0x68): multiple definition of `db_cpl::table_'
test.o:(.data.rel.local+0x68): first defined here
DbManager.o:(.data.rel.local+0x88): multiple definition of `db_kdm::table_'
test.o:(.data.rel.local+0x88): first defined here
DbManager.o:(.data.rel.local+0xc0): multiple definition of `db_monitor_errorinfo::table_'
test.o:(.data.rel.local+0xc0): first defined here
DbManager.o:(.data.rel.local+0xd8): multiple definition of `db_pkl::table_'
test.o:(.data.rel.local+0xd8): first defined here
DbManager.o:(.data.rel.local+0xf0): multiple definition of `db_spl::table_'
test.o:(.data.rel.local+0xf0): first defined here
DbManager.o:(.data.rel.local+0x104): multiple definition of `db_smuser::table_'
test.o:(.data.rel.local+0x104): first defined here
DbManager.o:(.data.rel.local+0x120): multiple definition of `db_showlog::table_'
test.o:(.data.rel.local+0x120): first defined here
DbManager.o:(.data.rel.local+0x140): multiple definition of `db_showtime::table_'
test.o:(.data.rel.local+0x140): first defined here
DbManager.o:(.data.rel.local+0x150): multiple definition of `db_systemfilelog::table_'
test.o:(.data.rel.local+0x150): first defined here
DbManager.o:(.data.rel.local+0x190): multiple definition of `db_transferlog::table_'
test.o:(.data.rel.local+0x190): first defined here
DbManager.o:(.data.rel.local+0x1a4): multiple definition of `db_urlhistory::table_'
test.o:(.data.rel.local+0x1a4): first defined here
DbManager.o:(.data.rel.local+0x1b0): multiple definition of `db_errordesc::table_'
test.o:(.data.rel.local+0x1b0): first defined here
DbManager.o:(.data.rel.local+0x1c4): multiple definition of `db_datadict::table_'
test.o:(.data.rel.local+0x1c4): first defined here
DbManager.o:(.data.rel.local+0x1d4): multiple definition of `db_assets_connection::table_'
test.o:(.data.rel.local+0x1d4): first defined here
DbManager.o:(.data.rel.local+0x1ec): multiple definition of `db_reel_connection::table_'
test.o:(.data.rel.local+0x1ec): first defined here
DbManager.o:(.data.rel.local+0x1fc): multiple definition of `db_secfilelog::table_'
test.o:(.data.rel.local+0x1fc): first defined here
DbManager.o:(.data.rel.local+0x0): multiple definition of `db_user::names'
test.o:(.data.rel.local+0x0): first defined here
DbManager.o:(.data.rel.local+0x6c): multiple definition of `db_kdm::names'
test.o:(.data.rel.local+0x6c): first defined here
DbManager.o:(.data.rel.local+0xc4): multiple definition of `db_pkl::names'
test.o:(.data.rel.local+0xc4): first defined here
DbManager.o:(.data.rel.local+0x144): multiple definition of `db_systemfilelog::names'
test.o:(.data.rel.local+0x144): first defined here
DbManager.o:(.data.rel.local+0x1f0): multiple definition of `db_secfilelog::names'
test.o:(.data.rel.local+0x1f0): first defined here
DbManager.o:(.data.rel.local+0x194): multiple definition of `db_urlhistory::names'
test.o:(.data.rel.local+0x194): first defined here
DbManager.o:(.data.rel.local+0xf4): multiple definition of `db_smuser::names'
test.o:(.data.rel.local+0xf4): first defined here
DbManager.o:(.data.rel.local+0x1a8): multiple definition of `db_errordesc::names'
test.o:(.data.rel.local+0x1a8): first defined here
DbManager.o:(.data.rel.local+0x1c8): multiple definition of `db_assets_connection::names'
test.o:(.data.rel.local+0x1c8): first defined here
DbManager.o:(.data.rel.local+0x1d8): multiple definition of `db_reel_connection::names'
test.o:(.data.rel.local+0x1d8): first defined here
DbManager.o:(.data.rel.local+0x124): multiple definition of `db_showtime::names'
test.o:(.data.rel.local+0x124): first defined here
DbManager.o:(.data.rel.local+0x160): multiple definition of `db_transferlog::names'
test.o:(.data.rel.local+0x160): first defined here
DbManager.o:(.data.rel.local+0xdc): multiple definition of `db_spl::names'
test.o:(.data.rel.local+0xdc): first defined here
DbManager.o:(.data.rel.local+0x108): multiple definition of `db_showlog::names'
test.o:(.data.rel.local+0x108): first defined here
DbManager.o:(.data.rel.local+0xa0): multiple definition of `db_monitor_errorinfo::names'
test.o:(.data.rel.local+0xa0): first defined here
DbManager.o:(.data.rel.local+0x1b4): multiple definition of `db_datadict::names'
test.o:(.data.rel.local+0x1b4): first defined here
DbManager.o:(.data.rel.local+0x20): multiple definition of `db_cpl::names'
test.o:(.data.rel.local+0x20): first defined here
collect2: ld returned 1 exit status
make: *** [libdbmanager.so] Error 1
在DbManager.cpp 和 test.cpp中都包含了一个自定义头文件 db_table.h 。。。
db_table.h在两cpp文件中都用到了,去除的话就显示未定义。
db_table.h是一个数据库表格类的头文件(MySQL++);
文件中 #ifndef TEST_H #define TEST_H #endif 都加了。
一直出现重定义。
请问这是为啥。求解。谢谢
[root@locahost test]# make -f makefile_new
g++ -fPIC -I./include/ -g -c test.cpp
g++ -fPIC -I./include/ -g -c DbManager.cpp
g++ -shared -fPIC -I./include/ -o libdbmanager.so test.o DbManager.o
DbManager.o:(.data.rel.local+0x14): multiple definition of `db_user::table_'
test.o:(.data.rel.local+0x14): first defined here
DbManager.o:(.data.rel.local+0x68): multiple definition of `db_cpl::table_'
test.o:(.data.rel.local+0x68): first defined here
DbManager.o:(.data.rel.local+0x88): multiple definition of `db_kdm::table_'
test.o:(.data.rel.local+0x88): first defined here
DbManager.o:(.data.rel.local+0xc0): multiple definition of `db_monitor_errorinfo::table_'
test.o:(.data.rel.local+0xc0): first defined here
DbManager.o:(.data.rel.local+0xd8): multiple definition of `db_pkl::table_'
test.o:(.data.rel.local+0xd8): first defined here
DbManager.o:(.data.rel.local+0xf0): multiple definition of `db_spl::table_'
test.o:(.data.rel.local+0xf0): first defined here
DbManager.o:(.data.rel.local+0x104): multiple definition of `db_smuser::table_'
test.o:(.data.rel.local+0x104): first defined here
DbManager.o:(.data.rel.local+0x120): multiple definition of `db_showlog::table_'
test.o:(.data.rel.local+0x120): first defined here
DbManager.o:(.data.rel.local+0x140): multiple definition of `db_showtime::table_'
test.o:(.data.rel.local+0x140): first defined here
DbManager.o:(.data.rel.local+0x150): multiple definition of `db_systemfilelog::table_'
test.o:(.data.rel.local+0x150): first defined here
DbManager.o:(.data.rel.local+0x190): multiple definition of `db_transferlog::table_'
test.o:(.data.rel.local+0x190): first defined here
DbManager.o:(.data.rel.local+0x1a4): multiple definition of `db_urlhistory::table_'
test.o:(.data.rel.local+0x1a4): first defined here
DbManager.o:(.data.rel.local+0x1b0): multiple definition of `db_errordesc::table_'
test.o:(.data.rel.local+0x1b0): first defined here
DbManager.o:(.data.rel.local+0x1c4): multiple definition of `db_datadict::table_'
test.o:(.data.rel.local+0x1c4): first defined here
DbManager.o:(.data.rel.local+0x1d4): multiple definition of `db_assets_connection::table_'
test.o:(.data.rel.local+0x1d4): first defined here
DbManager.o:(.data.rel.local+0x1ec): multiple definition of `db_reel_connection::table_'
test.o:(.data.rel.local+0x1ec): first defined here
DbManager.o:(.data.rel.local+0x1fc): multiple definition of `db_secfilelog::table_'
test.o:(.data.rel.local+0x1fc): first defined here
DbManager.o:(.data.rel.local+0x0): multiple definition of `db_user::names'
test.o:(.data.rel.local+0x0): first defined here
DbManager.o:(.data.rel.local+0x6c): multiple definition of `db_kdm::names'
test.o:(.data.rel.local+0x6c): first defined here
DbManager.o:(.data.rel.local+0xc4): multiple definition of `db_pkl::names'
test.o:(.data.rel.local+0xc4): first defined here
DbManager.o:(.data.rel.local+0x144): multiple definition of `db_systemfilelog::names'
test.o:(.data.rel.local+0x144): first defined here
DbManager.o:(.data.rel.local+0x1f0): multiple definition of `db_secfilelog::names'
test.o:(.data.rel.local+0x1f0): first defined here
DbManager.o:(.data.rel.local+0x194): multiple definition of `db_urlhistory::names'
test.o:(.data.rel.local+0x194): first defined here
DbManager.o:(.data.rel.local+0xf4): multiple definition of `db_smuser::names'
test.o:(.data.rel.local+0xf4): first defined here
DbManager.o:(.data.rel.local+0x1a8): multiple definition of `db_errordesc::names'
test.o:(.data.rel.local+0x1a8): first defined here
DbManager.o:(.data.rel.local+0x1c8): multiple definition of `db_assets_connection::names'
test.o:(.data.rel.local+0x1c8): first defined here
DbManager.o:(.data.rel.local+0x1d8): multiple definition of `db_reel_connection::names'
test.o:(.data.rel.local+0x1d8): first defined here
DbManager.o:(.data.rel.local+0x124): multiple definition of `db_showtime::names'
test.o:(.data.rel.local+0x124): first defined here
DbManager.o:(.data.rel.local+0x160): multiple definition of `db_transferlog::names'
test.o:(.data.rel.local+0x160): first defined here
DbManager.o:(.data.rel.local+0xdc): multiple definition of `db_spl::names'
test.o:(.data.rel.local+0xdc): first defined here
DbManager.o:(.data.rel.local+0x108): multiple definition of `db_showlog::names'
test.o:(.data.rel.local+0x108): first defined here
DbManager.o:(.data.rel.local+0xa0): multiple definition of `db_monitor_errorinfo::names'
test.o:(.data.rel.local+0xa0): first defined here
DbManager.o:(.data.rel.local+0x1b4): multiple definition of `db_datadict::names'
test.o:(.data.rel.local+0x1b4): first defined here
DbManager.o:(.data.rel.local+0x20): multiple definition of `db_cpl::names'
test.o:(.data.rel.local+0x20): first defined here
collect2: ld returned 1 exit status
make: *** [libdbmanager.so] Error 1
在DbManager.cpp 和 test.cpp中都包含了一个自定义头文件 db_table.h 。。。
db_table.h在两cpp文件中都用到了,去除的话就显示未定义。
db_table.h是一个数据库表格类的头文件(MySQL++);
文件中 #ifndef TEST_H #define TEST_H #endif 都加了。
一直出现重定义。
请问这是为啥。求解。谢谢
|
这个是因为你的db_table.h文件中定义了全局变量,比如db_cpl::names。因为你的两个C文件都包含了公共头文件,因此,在它们的.o文件都会被加入这些符号。当这些.o文件联接到一个程序或者库中时,就产生了符号重复问题。
解决的办法:在这些全局变量前面加上extern 修饰符就可以了。
一般的习惯是,将全局变量定义在它初始化的*.c或者*.cpp中,然后在公共头文件中使用extern声明该全局变量,以便该全局变量在源文件间共享。
解决的办法:在这些全局变量前面加上extern 修饰符就可以了。
一般的习惯是,将全局变量定义在它初始化的*.c或者*.cpp中,然后在公共头文件中使用extern声明该全局变量,以便该全局变量在源文件间共享。
|
你编绎成生两个对象文件test.o DbManager.o都包含了db_table.h里的定义,链接的时候自然会重复定义.
正确的做法是在头文件里只声明而不要定义
正确的做法是在头文件里只声明而不要定义