gpt4 book ai didi

C++ #include 不工作

转载 作者:太空宇宙 更新时间:2023-11-04 14:44:00 24 4
gpt4 key购买 nike

我正试图在 C++ 中包含这样的函数,但我不明白为什么它不起作用。我有 3 个文件。

test.cc

int test() {
std::cout << "This is a test" << std::endl;
}

测试.h

int test();

ma​​in.cc

#include "test.h"

int main() {

test();
return 0;
}

这是我得到的错误和我使用的命令。

c++ main.cc -o main
Undefined symbols for architecture x86_64:
"test()", referenced from:
_main in main-12ba52.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

最佳答案

这是罪魁祸首。

c++ main.cc -o main

你需要链接test.o。

c++ main.cc test.cc -o main

关于C++ #include 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24767331/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com