错误"未定义的引用'罪'"编译时(带-lm) [英] Error "undefined reference to `sin'" when compiling (with -lm)
问题描述
我已经下载并编译: http://leenissen.dk/fann/wp/
- cmake的版本2.8.11.2
- 海湾合作委员会(Ubuntu的/ Linaro的4.8.1-10ubuntu8)4.8.1
命令用来编译:
cmake的-D CMAKE_INSTALL_ preFIX:PATH = / usr中。
安装:
须藤使&放大器;&安培;须藤做安装
然后我去的例子/目录范文芳项目中,并尝试通过运行编译例子:
让所有
我得到一个错误:
-O3的gcc -o xor_train.c xor_train -lfann -lm
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so:未定义引用'罪'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so:未定义的引用`EXP
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so:未定义参考`COS
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so:未定义引用'登录'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so:未定义引用'战俘'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so:未定义参考`开方
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so:未定义引用'地板'
collect2:错误:LD返回1退出状态
使:*** [xor_train]错误1
更新:
- 我后面的库给出的指令
- 我检查另一台机器上,并提供指导按预期工作,所以我想我的环境是在某种方式配置错误。
有关共享库依赖一些更多的信息:
LDD /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so
Linux的vdso.so.1 => (0x00007fff3abfe000)
libc.so.6的= GT; /lib/x86_64-linux-gnu/libc.so.6(0x00007f6f3997c000)
/lib64/ld-linux-x86-64.so.2(0x00007f6f39f84000)
的建议与-Wl编译@迈克尔毛刺,-v
的/ usr / bin中/ LD --sysroot = / \\
--build-ID --eh帧HDR -m elf_x86_64 \\
--hash式= GNU --as急需\\
-dynamic-连接/lib64/ld-linux-x86-64.so.2 \\
-z relro -o xor_train \\
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o \\
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o \\
/usr/lib/gcc/x86_64-linux-gnu/4.8/crtbegin.o \\
-L / usr / lib目录/ GCC / x86_64的-Linux的GNU / 4.8 \\
-L / usr / lib目录/ GCC / x86_64的-Linux的GNU / 4.8 /../../../的x86_64-Linux的GNU \\
-L / usr / lib目录/ GCC / x86_64的-Linux的GNU / 4.8 /../../../../的lib \\
-L / lib目录/ x86_64的Linux的GNU的\\
-L / lib下的lib /../ -L / usr / lib目录/ x86_64的Linux的GNU的\\
-L / usr / lib目录/../ lib目录\\
-L / usr / lib目录/ GCC / x86_64的-Linux的GNU / 4.8 /../../ .. \\
-v /tmp/cc0AHZgU.o -lfann -lm -lgcc --as急需-lgcc_s --no-按需\\
-lc -lgcc --as急需-lgcc_s --no-按需\\
/usr/lib/gcc/x86_64-linux-gnu/4.8/crtend.o \\
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crtn.o
GNU LD(GNU Binutils的为Ubuntu)2.23.52.20130913
根源:在FANN库缺少的依赖(将发补丁作者)。这样的依赖性被称为<一href=\"http://www.gnu.org/software/libtool/manual/html_node/Inter_002dlibrary-dependencies.html\">inter库相关。
这可能会发生,一个构建一个共享库的 A 并没有正确的依赖集(假设的乙)。
在这种情况下共享库的 A 会因为它并不需要在编译过程中提供实现建立一个没有任何错误味精。
问题会出现缺乏图书馆的乙当一个人尝试创建依赖于一个可执行文件的 A
在此特定情况下,一个解决方案是修改一个CMake的配置文件,根据 CMake的手动
例changeline:
TARGET_LINK_LIBRARIES(范文芳米)
I've downloaded and compiled: http://leenissen.dk/fann/wp/
- cmake version 2.8.11.2
- gcc (Ubuntu/Linaro 4.8.1-10ubuntu8) 4.8.1
Command used to compile:
cmake -D CMAKE_INSTALL_PREFIX:PATH=/usr .
Installation:
sudo make && sudo make install
Then I go to examples/ directory inside fann project and try to compile examples by running:
make all
I'm getting an error:
gcc -O3 xor_train.c -o xor_train -lfann -lm
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so: undefined reference to `sin'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so: undefined reference to `exp'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so: undefined reference to `cos'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so: undefined reference to `log'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so: undefined reference to `pow'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so: undefined reference to `sqrt'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so: undefined reference to `floor'
collect2: error: ld returned 1 exit status
make: *** [xor_train] Error 1
Update:
- I've followed an instruction given by a library
- I've checked on another machine and provided instruction works as intended so I guess my environment is in a some way misconfigured.
Some more info about shared library dependencies:
ldd /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libfann.so
linux-vdso.so.1 => (0x00007fff3abfe000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6f3997c000)
/lib64/ld-linux-x86-64.so.2 (0x00007f6f39f84000)
As suggested by @michael-burr compiled with -Wl,-v
/usr/bin/ld --sysroot=/ \
--build-id --eh-frame-hdr -m elf_x86_64 \
--hash-style=gnu --as-needed \
-dynamic-linker /lib64/ld-linux-x86-64.so.2 \
-z relro -o xor_train \
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o \
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o \
/usr/lib/gcc/x86_64-linux-gnu/4.8/crtbegin.o \
-L/usr/lib/gcc/x86_64-linux-gnu/4.8 \
-L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu \
-L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib \
-L/lib/x86_64-linux-gnu \
-L/lib/../lib -L/usr/lib/x86_64-linux-gnu \
-L/usr/lib/../lib \
-L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../.. \
-v /tmp/cc0AHZgU.o -lfann -lm -lgcc --as-needed -lgcc_s --no-as-needed \
-lc -lgcc --as-needed -lgcc_s --no-as-needed \
/usr/lib/gcc/x86_64-linux-gnu/4.8/crtend.o \
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crtn.o
GNU ld (GNU Binutils for Ubuntu) 2.23.52.20130913
Root cause: missing dependencies in FANN library (Will send a patch to author). Such a dependency is called "inter library dependency".
It may happen that one build a shared library A and doesn't have correct dependencies set (let's say B). In such a case a shared library A will be build without any error msg as it's not required to provide implementation during compiling.
The problem will appear as a lack of library B when one try to create an executable file which depends on A.
In this specific case a solution is to modify a CMake configuration file according to CMake manual
Example changeline:
TARGET_LINK_LIBRARIES(fann m)
这篇关于错误&QUOT;未定义的引用'罪'&QUOT;编译时(带-lm)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!