【发布时间】:2021-09-18 18:20:06
【问题描述】:
我对 c++ 还很陌生,但是在 Google 的帮助下,在 Windows/Linux 中编写、编译和运行简单的 c++ 程序就像是一种魅力。
然而,尝试在 FreeBSD 中做同样的事情并不是那么简单。
我目前正在尝试编译以下程序:
#include <iostream>
int main(){
std::cout << "Hello.\n";
}
与
cpp -v test.cpp -o test
结果
FreeBSD clang version 10.0.1 (git@github.com:llvm/llvm-project.git llvmorg-10.0.1-0-gef32c611aa2)
Target: x86_64-unknown-freebsd12.2
Thread model: posix
InstalledDir: /usr/bin
(in-process)
"/usr/bin/cpp" -cc1 -triple x86_64-unknown-freebsd12.2 -E -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model static -mthread-model posix -mframe-pointer=all -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -v -resource-dir /usr/lib/clang/10.0.1 -internal-isystem /usr/include/c++/v1 -fdeprecated-macro -fdebug-compilation-dir /home/Administrator -ferror-limit 19 -fmessage-length 120 -fgnuc-version=4.2.1 -fobjc-runtime=gnustep -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -faddrsig -o test -x c++ test.cpp
clang -cc1 version 10.0.1 based upon LLVM 10.0.1 default target x86_64-unknown-freebsd12.2
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/v1
/usr/lib/clang/10.0.1/include
/usr/include
End of search list.
test.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^~~~~~~~~~
1 error generated.
尝试使用
定位 iostream 文件locate iostrem
没有结果。
仅供参考,操作系统是TwinCAT/BSD for Industrial PCs。根据我在谷歌上搜索的结果,我觉得这很相关。
有没有人愿意在正确的方向推动我解决这个问题?
【问题讨论】:
-
cpp是 C 预处理器。正确的前端程序是g++或clang++(取决于您安装的内容),它将使用查找 C++ 标准头文件所需的正确设置、选项和标志调用预处理器。 -
@Mat,感谢您的回答,但据我了解,大约十年前,FreeBSD 用 Clang 取代了 GCC。
-
某位程序员,谢谢!似乎我有办法解决这个问题。当我尝试使用 g++ 时,我得到“-sh: g++: not found”。与clang ++相同。但是,当我运行“man g++”时,我得到了 clang 的手册页。无论如何,这是否意味着我必须安装 g++ 或 clang++?
-
是的,您需要安装编译器才能实际编译任何东西。 :) C 预处理器通常作为标准安装,因为其他系统可能会使用它。
-
C++ 编译器是基础系统的一部分。使用
c++调用它。