使用g++包含来自不同文件夹的头文件

Include header file from different folder using g++

本文关键字:文件夹 文件 g++ 包含 使用      更新时间:2023-10-16

我试图安装FLTK库,发现头文件使用了不同的目录。所以我试着把它测试为:

\check.cpp in D:C++
#include <factorial.h> // Self-made header file in folder D:C++link
#include <iostream>
int main(){
// Blah blah and call to factorial function from factorial.h
}

请注意:链接文件夹包含1。string.exe(一个简单的exe文件(2。阶乘…

我正在尝试使用Cygwin从*D:\C++*编译check.cpp作为:

g++ this.cpp -ID:C++link -o done.exe

当链接文件夹(D:\C++\link(中只有factorial.h时,编译成功完成并生成一个可执行文件。

但是,当同一目录中有另一个文件string.exe时,g++会尝试将exe文件作为输入。。。确切的编译错误如下:

In file included from
/usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/bits/locale_classes.h:40:0,
from /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/bits/ios_base.h:41,
from /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/ios:42,
from /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/ostream:38,
from /usr/lib/gcc/x86_64-pc-cygwin/7.4.0/include/c++/iostream:39,
from check.cpp:2:
D:C++link/string:1:3: error: stray ‘220’ in program
MZ□       □□  □       @                                   □   □ □ □!□L□!This program cannot be run in DOS mode.
^
D:C++link/string:1:5: error: stray ‘3’ in program
MZ□       □□  □       @                                   □   □ □ □!□L□!This program cannot be run in DOS mode.
^
D:C++link/string:1:9: error: stray ‘4’ in program
MZ□       □□  □       @                                   □   □ □ □!□L□!This program cannot be run in DOS mode.

据我猜测,使用-ID:\C++\link\试图将string.exe作为输入或类似的东西。。。

您尝试过使用斜杠而不是反斜杠吗?/而不是

我认为您看到的是编译器在调用时试图包含string.exeCCD_ 3在CCD_。

另外,将文件夹称为"链接"有点令人困惑,"包含"会是一个更好的名称。

看起来你正在使用MinGW-这可能会对你有所帮助:MinGW包括的路径