你如何用 g++/C++ 保存链接?

How do you save links with g++/C++?

我正在编写一些 OpenGL 代码,/usr/lib 中的库链接变得非常笨拙:

g++ Application.cpp -lglfw -lGL -lGLEW

我不想搜索 around/can每次我想编译一些东西时都记不住库的确切名称,所以在我的项目文件夹中有一个名为 linkingsNeeded.txt 的文件。该文件只包含该命令,仅此而已。有没有办法保存链接列表,这样我就可以输入

g++ Application.cpp

并且不必手动处理链接?比如说,在 CPP 文件的#include 部分?

学习使用一些 build automation tool such as GNU make or ninja

然后您将编辑 Makefile(使用 make); this could be inspirational and just build your program by typing make. Most source code editors (like GNU emacs) 或者 IDE 可以很容易地配置为 运行 make 只需一个按键。

当然要invoke GCC as g++ -Wall -Wextra -g since you want all warnings and debug info (for the GDB调试器)。

另请阅读How to debug small programs and more about C++, perhaps even the n3337 准 C++11 标准。