dimanche 28 juin 2015

How to clean up C++ compiler commands?

I tried searching for a question like this as best as I could, but I simply don't know how exactly to ask the question. I apologize if this has been answered before, or if it is a trivial question. I am new to the large (and quite intimidating!) world of C++. I will try my best in the future.

Let me try to explain what I mean:

I am on Linux Ubuntu 14.04. On Ubuntu, to compile a C++ program I wrote, for example, let's say some file myProgram.cpp, I cd to its directory and type the following into the terminal:

g++ myProgram.cpp -o myProgram

This way, I can then type:

./myProgram

To run myProgram. This was simple and satisfactory -- and I learned this from reading the C++ Primer. After finding myself comfortable coding in C++, I decided to move onto giving myself a project, which involved using Image Magick, specifically, its C++ API: Magick++. However, now, if I wish to compile something, I have to type this ugly mess:

g++ `Magick++-config --cxxflags --cppflags` -o testMagick testMagick.cpp `Magick++-config --ldflags --libs`

To make my code compile and execute. This seems very messy, and when I was trying to see if CImg was any better, it turned out that it needed its own set of arguments like -lm, -lpthread and -lX11. It also turned out that to compile with C++11, I had to write -std=c++0x. So my question is:

Is there a way to simplify/clean up my compile statements in the terminal, or do I have to find out and use a specific set of arguments whenever I compile a different kind of program using a different API?

Aucun commentaire:

Enregistrer un commentaire