GCC LD:构造I386找不到符号
gcc ld: symbol(s) not found for architecture i386
我正在尝试在MacBook中测试gsl
的安装。我遵循此(1)和该(2)网站的说明,用于安装gsl
。
当我尝试使用brew install gsl
安装gsl
时,我会收到消息:
Warning: gsl 2.5 is already installed and up-to-date
但是,以上消息并不是担心的大原因。要检查gsl
是否正确安装,我正在尝试编译下面给出的测试代码(main.c
)。当我尝试编译此代码时,我遇到了麻烦。
#include <stdio.h>
#include <gsl/gsl_sf_bessel.h>
int main( int argc, const char *argv[] ) {
double x = 5.0 ;
double y = gsl_sf_bessel_J0( x ) ;
printf("J0(%g) = % .18en", x, y ) ;
return 0 ;
}
我正在尝试使用gcc -Wall -I/usr/local/inlcude main.c
编译上述代码。以下是我收到的错误消息。
Undefined symbols for architecture x86_64:
"_gsl_sf_bessel_J0", referenced from:
_main in ccHCdcTr.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
我读了此Stackoverflow帖子中给出的答案(因为它也指上述错误ld: symbol(s) not found for architecture x86_64
)。而且,我尝试使用gcc -m32 -Wall -I/usr/local/inlcude main.c
编译代码。但是现在,我得到了更多错误:
/var/folders/mp/z7xpkw3538z71904cdqhztv00000gn/T//ccrjsmhl.s:
46:11: warning: section "__textcoal_nt" is deprecated
.section __TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
/var/folders/mp/z7xpkw3538z71904cdqhztv00000gn/T//ccrjsmhl.s:46:11: note: change section name to "__text"
.section
__TEXT,__textcoal_nt,coalesced,pure_instructions
^ ~~~~~~~~~~~~~
ld: warning: The i386 architecture is deprecated for macOS (remove from the Xcode build setting: ARCHS)
Undefined symbols for architecture i386:
"_gsl_sf_bessel_J0", referenced from:
_main in ccAmYmtF.o
ld: symbol(s) not found for architecture i386
collect2: error: ld returned 1 exit status
在这两种情况下,我在编译后的工作目录中都没有在工作目录中看到任何对象文件(*.o
)。如何获得上述代码以正确运行?如何检查我的gsl
是否正确安装?我正在使用Macos Mojave版本10.14.3。
我尝试了以下步骤,并且它起作用。=)
我使用以下内容编译了该文件:
gcc -Wall -I/usr/local/include -c main.c -o main.o
然后使用下面给出的命令将其链接:
gcc -L/usr/local/lib main.o -lgsl -o main.out
现在,当我使用命令行运行可执行的main.out
时
./main.out
我将获得以下输出:
J0(5) = -1.775967713143382642e-01
相关文章:
- CMake 生成的 MSVC 项目找不到符号,即使为其相关 dll 正确生成了 lib 文件也是如此
- 错误:当我从"WinDbg"打开可执行文件时,找不到符号文件。默认导出 ntdll 的符号.dll
- 编译 GCC-5.0 OS X 狮子 dyld:找不到符号:__ZNKSt11logic_error4whatEv
- 在 Mac 上C++编译代码时处理“dyld:惰性符号绑定失败:找不到符号”错误
- 与 dlopen 的动态链接:找不到符号
- MacOS LD:找不到符号(x86_64)
- dyld:惰性符号绑定失败:找不到符号:_yylex
- OSX MOJAVE -LD:架构X86_64 clang找不到符号:错误:链接器命令失败,出口代码1
- LD:架构x86_64 clang找不到符号:错误:链接器命令失败,出口代码1(使用-v to See
- GCC LD:构造I386找不到符号
- dyld:惰性符号绑定失败:找不到符号.预期在:平面命名空间
- 链接库时找不到符号
- sql::mysql::get_driver_instance()找不到符号
- 在我的嵌套 for 循环中找不到符号"k"?
- 惰性符号绑定失败:找不到符号
- 链接器链接正确的文件,但找不到符号
- 链接器读取库,但在其中找不到符号?未解析的外部符号,但仅适用于 Win32 而不是 x64
- Ctypes 在使用 CMake 创建的共享库中找不到符号
- G++ LD:在体系结构x86_64找不到符号
- ShiftVector 模板类 - "找不到符号"