为C ++程序编写makefile
有人可以帮我写我的第一个makefile吗?
Can someone help me write my first makefile?
我有一个 helloworld.cpp
c $ c> /path/to/main/code/helloworld.cpp 。
然后我刚刚包括一个.h文件 #includeSFML / network.hpp
。
I have a helloworld.cpp
code in /path/to/main/code/helloworld.cpp
.
And then I have just included a .h file #include "SFML/network.hpp"
.
现在SFML库保存在 / path / to / SFML / Library
Now SFML library is saved in /path/to/SFML/Library
可以帮助我开始在这。
It would be great if someone can help me getting started in this. In the mean time, I am trying to read thru the literature but its very overwhelming.
虽然你可能需要学习传统的GNU Makefile语法,为了与其他项目一起工作,我建议使用CMake为自己的项目,因为它更简单和更直观。
Although you may need to learn the traditional GNU Makefile syntax in order to work with other projects, I recommend using CMake for your own projects because it is simpler and more intuitive.
一个CMake文件在项目的根目录(与这种情况下的源相同)中存放一个名为 CMakeLists.txt
的文件,如下所示:
A CMake file for your example would go in a file called CMakeLists.txt
in the root directory of your project (same as the source in this case) and look like this:
project(HelloWorld) # Name your project.
add_executable(helloworld helloworld.cpp) # Specify an executable to build.
link_directories(/path/to/SFML) # Tell it where your libraries are.
target_link_libraries(helloworld Library) # Tell it which library to link.
如果你想要能够#include来自SFML的头文件而不包括每次的目录名称,你还可以写:
If you want to be able to #include headers from SFML without including the directory name every time, then you can also write:
include_directories(SFML) # Tell it where your headers are.
有关编写CMake文件和运行CMake的更多文档可在网站。
Further documentation on writing CMake files and running CMake is available on the website.
最后,CMake经常给出一个嘈杂但无害的消息请求您在CMakeLists.txt文件顶部放置一行:
Lastly, CMake often gives a noisy but harmless message requesting that you put a line like this at the top of your CMakeLists.txt file:
cmake_minimum_required(VERSION 2.8) # Quell warnings.
干杯。