使用g ++包含来自不同文件夹的头文件
Include header file from different folder using g++
我试图安装 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
}
请注意:link 文件夹包含 1. string.exe(简单的 exe)2. factorial.h..
我正在尝试使用 cygwin 从 D:\C++\ 编译 check.cpp 作为:
g++ this.cpp -ID:\C++\link -o done.exe
当link文件夹(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 ‘0’ in program
MZ□ □□ □ @ □ □ □ □!□L□!This program cannot be run in DOS mode.
^
D:\C++\link/string:1:5: error: stray ‘’ in program
MZ□ □□ □ @ □ □ □ □!□L□!This program cannot be run in DOS mode.
^
D:\C++\link/string:1:9: error: stray ‘’ in program
MZ□ □□ □ @ □ □ □ □!□L□!This program cannot be run in DOS mode.
据我所知,使用 -ID:\C++\link\ 试图将 string.exe 作为输入或类似的东西...
您是否尝试过使用斜线而不是反斜线? /
而不是 \
?
我想你看到的是编译器在调用时试图包含 string.exe
#include <string>
<iostream>
.
某处
同时调用文件夹 'link' 有点令人困惑,'include' 会是一个更好的名称。
您似乎在使用 MinGW - 这可能对您有所帮助:MinGW include path howto
[无法作为答案发表评论。]
我试图安装 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
}
请注意:link 文件夹包含 1. string.exe(简单的 exe)2. factorial.h.. 我正在尝试使用 cygwin 从 D:\C++\ 编译 check.cpp 作为:
g++ this.cpp -ID:\C++\link -o done.exe
当link文件夹(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 ‘0’ in program
MZ□ □□ □ @ □ □ □ □!□L□!This program cannot be run in DOS mode.
^
D:\C++\link/string:1:5: error: stray ‘’ in program
MZ□ □□ □ @ □ □ □ □!□L□!This program cannot be run in DOS mode.
^
D:\C++\link/string:1:9: error: stray ‘’ in program
MZ□ □□ □ @ □ □ □ □!□L□!This program cannot be run in DOS mode.
据我所知,使用 -ID:\C++\link\ 试图将 string.exe 作为输入或类似的东西...
您是否尝试过使用斜线而不是反斜线? /
而不是 \
?
我想你看到的是编译器在调用时试图包含 string.exe
#include <string>
<iostream>
.
同时调用文件夹 'link' 有点令人困惑,'include' 会是一个更好的名称。
您似乎在使用 MinGW - 这可能对您有所帮助:MinGW include path howto
[无法作为答案发表评论。]