c++ api程序编译不过,报错undefined reference to...

我的编译环境如下:

database@wale-virtual-machine:$ cat /etc/issue
Ubuntu 16.04.4 LTS \n \l

database@wale-virtual-machine:$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

我的makefile如下:

CFLAGS = -g -Wall -std=c++11 -fPIC -DLINUX -DLOGGING_LEVEL_2 -O2 
INCLUDES= -I../../include
OBJS=testWriting.o

all: $(OBJS)
    g++ -L../../bin/linux_x64 -L../../bin/mingw_x64 -L../../bin/vx2017_x64 $(OBJS) $(CFLAGS)  -lDolphinDBAPI  -L../../bin  -Wl,-rpath,.:../../bin/linux_x64/ -o testWriting 
testWriting.o: testWriting.cpp
    g++ $(CFLAGS) $(INCLUDES) -c testWriting.cpp -o testWriting.o
clean:
    rm *.o testWriting  core -rf

编译时,错误信息如下:

database@wale-virtual-machine:~/api-cplusplus/example/testWriting$ make
g++ -g -Wall -std=c++11 -fPIC -DLINUX -DLOGGING_LEVEL_2 -DLINUX  -O0  -I../../include -c testWriting.cpp -o testWriting.o
g++ -D_GLIBCXX_USE_CXX11_ABI=0 -L./  testWriting.o -g -Wall -std=c++11 -fPIC -DLINUX -DLOGGING_LEVEL_2 -DLINUX  -O0   -lDolphinDBAPI   -L./  -Wl,-rpath,. -o testWriting 
testWriting.o: In function `createDemoTable(long, long, int)':
/home/database/api-cplusplus/example/testWriting/testWriting.cpp:43: undefined reference to `dolphindb::Util::createTable(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::vector<dolphindb::DATA_TYPE, std::allocator<dolphindb::DATA_TYPE> > const&, int, int)'
testWriting.o: In function `createDemoTable1(long, long, int)':
/home/database/api-cplusplus/example/testWriting/testWriting.cpp:277: undefined reference to `dolphindb::DBConnection::connect(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)'
/home/database/api-cplusplus/example/testWriting/testWriting.cpp:293: undefined reference to `dolphindb::DBConnection::run(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<dolphindb::SmartPointer<dolphindb::Constant>, std::allocator<dolphindb::SmartPointer<dolphindb::Constant> > >&, int, int)'
collect2: error: ld returned 1 exit status
Makefile:6: recipe for target 'all' failed
make: *** [all] Error 1

请问可能是什么原因?先谢了!

请先 登录 后评论

1 个回答

logger

当编译链接时遇到类似的undefined reference to "std::__cxx11 ***"这种错误,那基本就是遇到了C++ ABI问题了。所谓ABI,是指应用程序二进制接口(Application Binary Interface),详见GCC提供的手册 https://gcc.gnu.org/onlinedoc... 

从DolphinDB c++ api的readme中也提到:为了兼容旧的编译器,libDolphinDBAPI.so编译时使用了-D_GLIBCXX_USE_CXX11_ABI=0的选项,因此你在编译api程序的时候也应该加入该选项。





请先 登录 后评论