小编sca*_*ers的帖子

由于在 Bjarne Stroustrup "Programming and Practices using c++" 中找不到符号导致的链接错误

我是 C++(以及一般编译语言)的新手,正在 Bjarne Stroustrup“使用 C++ 进行编程和实践”的第 8 章末尾进行练习,但是当我尝试编译代码时出现以下错误

?  Desktop g++ -std=c++11 *.cpp -o use
Undefined symbols for architecture x86_64:
  "_foo", referenced from:
      print_foo() in my-4f7853.o
      _main in use-46cb26.o
     (maybe you meant: __Z9print_foov)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)

我也试过使用g++ -c my.cpp use.cpp后跟,g++ -o use.exe my.o use.o但这给出了同样的错误。我尝试的另一种方法是g++ -c use.cpp -o use.exe,但是use.exe在运行时没有产生任何输出。源代码文件是

我的.h

extern int foo;
void print_foo(); …
Run Code Online (Sandbox Code Playgroud)

c++ g++ clang linker-errors

4
推荐指数
1
解决办法
121
查看次数

标签 统计

c++ ×1

clang ×1

g++ ×1

linker-errors ×1