在使用GNU Make和clang的架构x86_64中没有找到ld: symbol(s)
ld: symbol(s) not found for architecture x86_64 using GNU Make and clang
我得到一个ld: symbol(s) not found for architecture x86_64
错误。我确实在之前的帖子中做了彻底的搜索,但没有找到解决方案。
作为测试,我正在编译一个程序test.cpp:
#include <iostream>
using namespace std;
int main(){
return 0;
}
与Makefile:
CXX=g++
CXXFLAGS=-g -Wall -W -Wconversion -Wshadow -Wcast-qual -Wwrite-strings $(shell root-config --cflags --glibs)
CPPFLAGS+=-MMD -MP
LDFLAGS=-g $(shell root-config --ldflags)
LDLIBS=$(shell root-config --libs)
test.o: test.cpp
test: test.o
-include test.d
在我的linux计算机上运行make test
会产生以下正确的输出:
CAM ~/Wenu $ make test
g++ -g -Wall -W -Wconversion -Wshadow -Wcast-qual -Wwrite-strings -pthread -m64 -I/cvmfs/lhcb.cern.ch/lib/RootConfig/pro/x86_64-slc5-gcc46-opt/root/include -L/cvmfs/lhcb.cern.ch/lib/RootConfig/pro/x86_64-slc5-gcc46-opt/root/lib -lGui -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic -MMD -MP -c -o test.o test.cpp
cc -g -m64 test.o -L/cvmfs/lhcb.cern.ch/lib/RootConfig/pro/x86_64-slc5-gcc46-opt/root/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic -o test
CAM ~/Wenu $
在我的Mac上编译它在链接阶段失败,ld: symbol(s) not found for architecture x86_64
错误:
MAC ~/Transmit/Wenu $ make test
g++ -g -Wall -W -Wconversion -Wshadow -Wcast-qual -Wwrite-strings -pthread -m64 -I/opt/local/root-v5-34-00/include -L/opt/local/root-v5-34-00/lib -lGui -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lpthread -Wl,-rpath,/opt/local/root-v5-34-00/lib -lm -ldl -MMD -MP -c -o test.o test.cpp
i686-apple-darwin11-llvm-g++-4.2: -lGui: linker input file unused because linking not done
i686-apple-darwin11-llvm-g++-4.2: -lCore: linker input file unused because linking not done
i686-apple-darwin11-llvm-g++-4.2: -lCint: linker input file unused because linking not done
i686-apple-darwin11-llvm-g++-4.2: -lRIO: linker input file unused because linking not done
i686-apple-darwin11-llvm-g++-4.2: -lNet: linker input file unused because linking not done
i686-apple-darwin11-llvm-g++-4.2: -lHist: linker input file unused because linking not done
i686-apple-darwin11-llvm-g++-4.2: -lGraf: linker input file unused because linking not done
i686-apple-darwin11-llvm-g++-4.2: -lGraf3d: linker input file unused because linking not done
i686-apple-darwin11-llvm-g++-4.2: -lGpad: linker input file unused because linking not done
i686-apple-darwin11-llvm-g++-4.2: -lTree: linker input file unused because linking not done
i686-apple-darwin11-llvm-g++-4.2: -lRint: linker input file unused because linking not done
i686-apple-darwin11-llvm-g++-4.2: -lPostscript: linker input file unused because linking not done
i686-apple-darwin11-llvm-g++-4.2: -lMatrix: linker input file unused because linking not done
i686-apple-darwin11-llvm-g++-4.2: -lPhysics: linker input file unused because linking not done
i686-apple-darwin11-llvm-g++-4.2: -lMathCore: linker input file unused because linking not done
i686-apple-darwin11-llvm-g++-4.2: -lThread: linker input file unused because linking not done
i686-apple-darwin11-llvm-g++-4.2: -lpthread: linker input file unused because linking not done
i686-apple-darwin11-llvm-g++-4.2: -rpath: linker input file unused because linking not done
i686-apple-darwin11-llvm-g++-4.2: /opt/local/root-v5-34-00/lib: linker input file unused because linking not done
i686-apple-darwin11-llvm-g++-4.2: -lm: linker input file unused because linking not done
i686-apple-darwin11-llvm-g++-4.2: -ldl: linker input file unused because linking not done
cc -g -m64 test.o -L/opt/local/root-v5-34-00/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lpthread -Wl,-rpath,/opt/local/root-v5-34-00/lib -lm -ldl -o test
Undefined symbols for architecture x86_64:
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int) in test.o
"std::ios_base::Init::~Init()", referenced from:
___tcf_0 in test.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [test] Error 1
任何帮助都将是非常感激的。
如果这是相关的,我有一个64位的Mac OS X 10.7.5,我有一个编译器,XCode的命令行工具:
MAC ~/Transmit/Wenu $ clang --version
Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.4.2
Thread model: posix
ROOT是我在程序中使用的c++库的集合。
在我的linux计算机上运行make test会产生以下正确的输出
这只在偶然情况下起作用:您正在将C++
程序与cc
链接。如果您使用更多的C++
,它将停止在Linux上工作,例如尝试将cout << "Hello" << endl;
放入main
。
我的文件有一个cpp扩展名,所以我不明白为什么要用cc。
因为从test.o
生成test
的默认make规则使用$CC
,而不是$CXX
。
您可以通过以下几种方式之一修复此问题:
- 强制
$CC
也为g++
,或者 - 在从
test.o
生成test
时更改Makefile
使用非默认规则,或 - 使
test
依赖于test.cpp
(make
将使用正确的默认规则,如果你这样做)
相关文章:
- ld:bind_at_load和-bitcode_bundle(Xcode设置ENABLE_bitcode=YES)不能
- 使用JsonCpp将数据返回到带有pybind11的python会在python调用中产生Symbol not foun
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- CppSQLite 抛出"LNK2019: unresolved external symbol"错误
- C++ 中的编译错误:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- /usr/bin/ld: cannot find -lc++
- 解决"ld: library not found for -ltensorflow_framework.2.3.0"
- 从不同目录执行时"symbol lookup error:",否则从构建目录执行时按预期工作
- 编译 Boost 时在 OS X 上的"ld:未知选项:-soname"
- 使 ld 忽略来自 /etc/ld.so.conf 的目录
- 编译问题:在函数"_start"中:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 有错误"Undefined symbols for architecture x86_64"和"ld: symbol(s) not found for architecture x86_64"
- 链接错误"ld: fatal: Symbol referencing errors."
- 获取符号错误:'ld: symbol(s) not found'
- OpenCV 3 的"ld: symbol(s) not found for architecture x86_64"
- LD 链接器错误"cpu model hidden symbol"
- 编译 cmake 代码时获取"ld: symbol(s) not found for architecture x86_64"
- 操作系统字距错误: "ld: symbol(s) not found for architecture x86_64"
- g++ ld: symbol(s) not found for architecture x86_64 -没有更具体的错
- 在使用GNU Make和clang的架构x86_64中没有找到ld: symbol(s)