.so中存在的符号,compiled.o引用它,但链接失败 我有一个奇怪的问题,把C++和Leptonica连接起来。正常的函数调用工作正常,但我需要库中的函数,这些函数最初没有在.so库中公开。因此,我在源代码中搜索了两个有趣的函数,删除了static关键字,因此它们看起来类似于公开的函数。经过一番清理,我把整个图书馆重新改造了一番。.so文件看起来正常: nm liblept.so.5.0.0 ... 000000000009d010 T dewarpGetMeanVerticals 000000000009d160 T dewarpGetTextlineCenters 000000000009d8f0 T dewarpIsLineCoverageValid nm liblept.so.5.0.0 ... 000000000009d010吨脱水机平均垂直 000000000009d160吨DewarpGetTextLineCenter 000000000009d8f0 T DewarpislineCoverage有效

.so中存在的符号,compiled.o引用它,但链接失败 我有一个奇怪的问题,把C++和Leptonica连接起来。正常的函数调用工作正常,但我需要库中的函数,这些函数最初没有在.so库中公开。因此,我在源代码中搜索了两个有趣的函数,删除了static关键字,因此它们看起来类似于公开的函数。经过一番清理,我把整个图书馆重新改造了一番。.so文件看起来正常: nm liblept.so.5.0.0 ... 000000000009d010 T dewarpGetMeanVerticals 000000000009d160 T dewarpGetTextlineCenters 000000000009d8f0 T dewarpIsLineCoverageValid nm liblept.so.5.0.0 ... 000000000009d010吨脱水机平均垂直 000000000009d160吨DewarpGetTextLineCenter 000000000009d8f0 T DewarpislineCoverage有效,c++,static,linker,C++,Static,Linker,编译到.o文件并观察它: g++ -c -std=c++11 -I../leptonica/src/src/ preproc.cpp -L../leptonica/src/.libs/ -llept -o preproc nm preproc ... U dewarpGetMeanVerticals U dewarpIsLineCoverageValid g++-c-std=c++11-I../leptonica/src/src/preproc.cpp-L../leptonica/src/.li

编译到.o文件并观察它:

g++ -c -std=c++11 -I../leptonica/src/src/ preproc.cpp -L../leptonica/src/.libs/ -llept -o preproc nm preproc ... U dewarpGetMeanVerticals U dewarpIsLineCoverageValid g++-c-std=c++11-I../leptonica/src/src/preproc.cpp-L../leptonica/src/.libs/-llept-o preproc 纳米预处理 ... U dewarpGetMeanVerticals U DewarpislineCoverage有效 而不带-c标志的相同编译会导致

/tmp/ccCPqS1R.o: In function `_dewarpGetTextlineCenters(Pix*, int)': preproc.cpp:(.text+0x3d5): undefined reference to `dewarpGetMeanVerticals' /tmp/ccCPqS1R.o: In function `_dewarpBuildPageModel(L_Dewarp*, char const*)': preproc.cpp:(.text+0x81d): undefined reference to `dewarpIsLineCoverageValid' collect2: error: ld returned 1 exit status /tmp/ccCPqS1R.o:在函数“DewarpGetTextLineCenter(Pix*,int)”中: 预编程cpp:(.text+0x3d5):未定义对“dewarpGetMeanVerticals”的引用 /tmp/ccCPqS1R.o:在函数“dewarpBuildPageModel(L_Dewarp*,char const*)”中: preproc.cpp:(.text+0x81d):对“dewarpIsLineCoverageValid”的未定义引用 collect2:错误:ld返回了1个退出状态 我做错了什么

提前感谢:Balázs

我认为如果您想在so中公开这些函数,您可能需要这些函数周围的extern“C”关键字。因为名字在C++编译器中似乎没有被破坏,所以这可能不是这样。
我注意到您正在向我们展示liblept.so.5.0.0中的内容,以及与liblept.so的链接。您是否需要更新符号链接,以便针对正确的.so文件进行链接?

我注意到您正在向我们展示liblept.so.5.0.0中的内容以及针对liblept.so的链接。您是否需要更新符号链接,以便根据正确的.so文件进行链接?
nm
不是这里最好的工具,请尝试
readelf--dyn syms-W
。可能的重复。您是否已对客户端代码可见的新外部函数进行了正确声明?很抱歉,我发现了问题:在/usr/local/lib中有一个.so的旧实例,我忘了。移除它修复了问题。谢谢克莱布兰科的提示!另一方面,应用程序中的符号似乎被弄坏了(否则链接器就不知道它们的类型)。也许OP在应用程序代码中缺少外部“C”?这是注释,不是答案。