链接器与NBIS库失败

时间:2016-07-30 07:01:58

标签: c++ linker-errors

我正在尝试在OS X上使用NBIS库,但我遇到了一个问题:

Undefined symbols for architecture x86_64:
  "distance(int, int, int, int)", referenced from:
      _main in test-2db11c.o
ld: symbol(s) not found for architecture x86_64

我尝试使用.a存档以及那里的.o文件 - 没有运气 - 同样的问题。

我正在尝试编译的源代码(test.cpp):

#include <iostream>
#include <lfs.h>

using namespace std;

int main() {
    cout << distance(1, 2, 3, 4) << endl;
}

以下是我尝试过的执行行(失败):

$> g++ -std=c++11 -ggdb -g -Wall test.cpp -o test.bin -lm -lc++ 
$> g++ -std=c++11 -ggdb -g -Wall test.cpp -o test.bin -lm -lc++ -L/NBIS/Main/lib -lmindtct 
$> g++ -std=c++11 -ggdb -g -Wall test.cpp -o test.bin -lm -lc++ -L/NBIS/Main/lib -l:libmindtct.a 
$> g++ -std=c++11 -ggdb -g -Wall test.cpp /NBIS/Main/lib/libmindtct.a -o test.bin -lm -lc++ 
$> g++ -std=c++11 -ggdb -g -Wall test.cpp /NBIS/Main/lib/util.o -o test.bin -lm -lc++ 

为了确认库实际上已经声明了方法,我检查了libmindtct.a存档中的内容:

$> ar t libmindtct.a
__.SYMDEF SORTED
<MANY FILES .o>
util.o
<SOME MORE .o FILES>

$> ar -x libmindtct.a util.o
$> nm util.o
                 U ___stderrp
00000000000008d0 T _angle2line
                 U _atan2
0000000000000a10 T _closest_dir_dist
0000000000000600 T _distance
00000000000008a0 T _find_incr_position_dbl
                 U _fmod
                 U _free
                 U _fwrite
0000000000000650 T _in_int_list
0000000000000920 T _line2direction
                 U _malloc
0000000000000000 T _maxv
0000000000000360 T _minmaxs
00000000000001b0 T _minv
0000000000000690 T _remove_from_int_list
0000000000000630 T _squared_distance

要编译库我使用以下内容:

$> cd ~/Downloads/NBIS/
$> ./setup.sh /NBIS/Main --64
$> make config && make it && make install LIBNBIS=no && make catalog

1 个答案:

答案 0 :(得分:0)

来自NBIS的

lfs.h仅为C.您需要为lfs.h启用C链接:

extern "C" {
        #include <lfs.h>
}

此外,您无需使用libc++手动关联libmg++