lad*_*ads 5 c++ windows g++ path
我有一个 C++ 程序 test.cpp,我想将两个 .lib 文件链接到它(fhlib.lib 和 gc_lib.lib)。我的 .lib 文件与我的 .cpp 程序位于同一文件夹中。我在 Windows 7 上。
到目前为止我尝试过的内容如下:
g++ -o main main.cpp -L/Users\Documents\Visual Studio 2015\Projects\My Project -lfhlib
Run Code Online (Sandbox Code Playgroud)
但我得到一个
No such file or directory error.
Run Code Online (Sandbox Code Playgroud)
我确定路径是正确的,因为我是从 Properties->Location 复制的。但我确实删除了“C:\”,因为它没有编译。
编辑:我发现这个http://www.mingw.org/wiki/Specify_the_libraries_for_the_linker_to_use。
所以我尝试使用
"-I" instead of "-l"
Run Code Online (Sandbox Code Playgroud)
但仍然不起作用。我得到:
undefined reference to 'fh_set'...
Run Code Online (Sandbox Code Playgroud)
如果您在 Windows 上使用 g++ 进行编译,我猜您正在使用 MinGW:MinGW 依赖于 .a 库。使用“-l”选项时,编译器正在寻找扩展名为 .a 的库文件。
.lib 格式的库是用 Visual Studio 编译的:你不能这样使用它。如果您有源代码或考虑将您的项目迁移到 Visual Studio,请使用 MinGW 编译您的库。