我正在尝试使用libtommath库.我在Ubuntu linux上使用NetBeans IDE作为我的项目.我已经下载并构建了库,我已经完成了'make install'以将生成的.a文件放入/ usr/lib /并将.h文件放入/ usr/include
它似乎是正确地找到文件(因为我不再得到这些错误,我在安装到/ usr目录之前做了这些错误).
但是,当我创建一个简单的main来调用mp_init(在库中)时,当我尝试创建项目时出现以下错误:
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/main.o.d
gcc -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o main.c
mkdir -p dist/Debug/GNU-Linux-x86
gcc -o dist/Debug/GNU-Linux-x86/cproj1 build/Debug/GNU-Linux-x86/main.o
build/Debug/GNU-Linux-x86/main.o: In function 'main':
/home/[[myusername]]/NetBeansProjects/CProj1/main.c:18: undefined reference to `mp_init'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/cproj1] Error 1
Run Code Online (Sandbox Code Playgroud)
因此,看起来链接器无法在库中找到该函数,但它就在那里,所以我只是不知道是什么原因造成的.
如果我直接输入gcc命令并跳过makefile,我会得到同样的错误,我也确保静态库也用gcc编译.
编辑添加:
如果我直接编译并使用-l或-L添加库,我会得到同样的错误:
$ gcc -l /usr/lib/libtommath.a main.c
/usr/bin/ld: cannot find -l/usr/lib/libtommath.a
collect2: ld returned 1 exit status
$ gcc -llibtommath.a main.c
/usr/bin/ld: cannot find -llibtommath.a …Run Code Online (Sandbox Code Playgroud) 我最近在ubuntu机器上安装了hdf5库,现在无法链接到导出的函数.我写了一个简单的测试脚本readHDF.cpp来解释这个问题:
#include <hdf5.h>
int main(int argc, char * argv[])
{
hid_t h5_file_id = H5Fopen(argv[1], H5F_ACC_RDWR, H5P_DEFAULT);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译命令是
g++ -Wl,-rpath,$HOME/hdf5/lib -I$HOME/hdf5/include \
-L$HOME/hdf5/lib -l:$HOME/hdf5/lib/libhdf5.so readHDF.cpp
Run Code Online (Sandbox Code Playgroud)
返回以下错误
/tmp/cc6DXdxV.o: In function `main':
readHDF.cpp:(.text+0x1f): undefined reference to `H5check_version'
readHDF.cpp:(.text+0x3c): undefined reference to `H5Fopen'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
我很困惑,因为nm命令似乎说该函数已被导出:
nm -C $HOME/hdf5/lib/libhdf5.so | grep H5check_version
Run Code Online (Sandbox Code Playgroud)
返回
0000000000034349 T H5check_version
Run Code Online (Sandbox Code Playgroud)
和类似的结果H5Fopen.什么可能出错?不确定它是否有帮助,但如果我注释掉H5Fopen脚本的部分,那么它编译得很好:
#include <hdf5.h>
int main(int argc, char * argv[])
{
hid_t …Run Code Online (Sandbox Code Playgroud) 我在Ubuntu上针对glib编译一个简单的示例程序时遇到了麻烦.我收到以下错误.我可以让它编译但不与-c标志链接,我相信这意味着我安装了glib标头,但它没有找到共享对象代码.另请参阅下面的Make文件.
$> make re
gcc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lglib-2.0 re.c -o re
/tmp/ccxas1nI.o: In function `print_uppercase_words':
re.c:(.text+0x21): undefined reference to `g_regex_new'
re.c:(.text+0x41): undefined reference to `g_regex_match'
re.c:(.text+0x54): undefined reference to `g_match_info_fetch'
re.c:(.text+0x6e): undefined reference to `g_print'
re.c:(.text+0x7a): undefined reference to `g_free'
re.c:(.text+0x8b): undefined reference to `g_match_info_next'
re.c:(.text+0x97): undefined reference to `g_match_info_matches'
re.c:(.text+0xa7): undefined reference to `g_match_info_free'
re.c:(.text+0xb3): undefined reference to `g_regex_unref'
collect2: ld returned 1 exit status
make: *** [re] Error 1
Run Code Online (Sandbox Code Playgroud)
Makefile 用过的:
# Need to …Run Code Online (Sandbox Code Playgroud)