Swap unix compiler flags with a shorter one

I've been running ns3 sumulations in linux and every time I compiled I had to type

g++ -Wall -o simulacija simulacija.cc -DNS3_ASSERT_ENABLE -DNS3_LOG_ENABLE `pkg-config --libs --cflags
libns3.16-core-debug libns3.16-network-debug libns3.16-applications-debug libns3.16-internet-debug
libns3.16-point-to-point-debug libns3.16-point-to-point-layout-debug libns3.16-csma-debug
libns3.16-csma-layout-debug libns3.16-topology-read-debug libns3.16-wifi-debug`

Is there a way to shorten the flags to eg:

g++ -Wall simulacija.cc -o simulacija -my_params

Thank you

Answers


The GCC compiler supports the @ notation to embed a sequence of arguments inside a file. Read near end of GCC overall options page.

So you could put in some file params.args the following lines

-Wall
-I /usr/local
-DNS3_ASSERT_ENABLE 
-DNS3_LOG_ENABLE
-O

and just invoke

g++ @params.args  simulacija.cc -o simulacija

You could have a Makefile rule to build that params.args (e.g. with pkg-config etc...)

Actually, it is time to learn how to use GNU make.

Notice that the @ option is not understood by some other compilers like GCC handles it.


You can create a shell script myparams.sh that outputs your parameters:

#!/bin/sh
echo -n "-DNS3_ASSERT_ENABLE -DNS3_LOG_ENABLE"
pkg-config --libs --cflags libns3.16-core-debug [...]

Now you can run

g++ -Wall simulacija.cc -o simulacija `./myparams.sh`

(Don't forget to chmod +x myparams.sh)


Need Your Help

Read text file from position in Java

java text io

I need to read char[] (size is COUNT) from text file from OFFSET with specified Charset. COUNT and OFFSET are in characters, not in bytes.

Problem with NSStrings and UIAlertView

objective-c nsstring declaration exc-bad-access uialertview

I have having a very odd issue when utilizing this UIAlertView. When viewing a Physician they have several offices. Upon selecting one you get an alert that offers to call this location or display ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.