GCC 4.8在链接libmagic时失败
GCC 4.8 fails while linking with libmagic
我正在努力解决这个问题,同时链接我的代码对libmagic:
test.c:(.text+0x16): undefined reference to `magic_open'
test.c:(.text+0x50): undefined reference to `magic_load'
test.c:(.text+0x60): undefined reference to `magic_error'
test.c:(.text+0x84): undefined reference to `magic_close'
test.c:(.text+0x9e): undefined reference to `magic_file'
test.c:(.text+0xba): undefined reference to `magic_close'
collect2: ld returned 1 exit status
然而,这个问题只出现在gcc版本> 4.4时。为了进行编译,我使用以下命令:
gcc -L/usr/lib/ -lmagic test.c -o test
使用libmagic的示例代码可以在这里找到。我检查过了,这个问题也出现了。显然libmagic和libmagic-dev已经安装在我的系统上了(Ubuntu 14.04)。
是否有任何方法来处理这个问题,而不是降级gcc版本?
这是一个常见问题解答,与您的GCC版本无关。
我不认为你的编译成功的gcc-4.3
gcc
的参数顺序很重要(例如this);对象文件和库应该放在最后(从高级到低级)。试着与
gcc -Wall -g test.c -lmagic -o mytest
顺便说一句,不要把你的可执行文件命名为test
(但例如mytest
),因为test
通常是shell内置的
相关文章:
- 如果没有malloc,链表实现将失败
- 模板参数替换失败,并且未完成隐式转换
- 具有默认模板参数的多态类的模板推导失败
- 视图中的参数推导失败:take_while
- 链接到自行创建的dll失败
- 带有特殊路径部分的"std::filesystem::weakly_canonical"失败
- GetShortPathName在网络驱动器上使用中文文件夹时失败
- gcc和c++17的过载解析失败
- 为什么使用 P/Invoke 调用 dll 时,某些计算机中的 LoadLibrary 失败?
- 在WSL:configure_file上对config_file的每次调用都失败:配置文件时出现问题
- 使用 GCC 卸载的 OpenMP 卸载失败,并出现"Ptx assembly aborted due to errors"
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- 链接阶段在Ubuntu上失败,但在MacOS上失败
- 从父数组测试用例构造二叉树失败
- LibGit2 SSH身份验证失败
- 如何让LLDB在成功时退出,在失败时等待
- VS2017,C++包含目录与附加包含目录,子文件夹包含失败-但为什么
- 生成MRPT库时cmake配置失败
- 为什么除非添加括号,否则构造函数上的模板替换会失败?
- GCC 4.8在链接libmagic时失败