erogol
erogol

Reputation: 13624

How can I define custom build command instead of "make all" in a C++ Eclipse projects?

I imported an existing make file project to eclipse. I want to compile the code with a custom make argument instead of make all like make test. How can I add these different make calls to project in Eclipse Luna?

Upvotes: 2

Views: 3612

Answers (4)

user184968
user184968

Reputation:

The answer from URaoul helped me find another answer. (Update: Later I realized that the more correct answer than mine is to use "Build Configurations")

There is a menu command "Make Targets". You can find it in menu: Project/Make Targes. Or you can simply press "Shift-F9".

So you need to create one or a few targes. So for my makefile:

.PHONY: all test autotest

all: program

program: main.o
    $(CXX) $(LDFLAGS) -o $@ $^
test:
    ./program

autotest:
    echo "Autotests"
    ./program
    echo "Autotests completed"

clean:
    rm *.o program

I created three targets in "Make target": enter image description here

One of them is "run my autotests" which has a custom build command:

enter image description here

One of them is all, which has a default command: enter image description here

Upvotes: 4

URaoul
URaoul

Reputation: 553

From http://help.eclipse.org/luna/topic/org.eclipse.cdt.doc.user/getting_started/cdt_w_import.htm?cp=10_1_3

Open the project properties (right mouse on project name in the Project Explorer view and select Properties at the bottom on the context menu).

On the C/C++ Build Page, on its Builder Settings tab, uncheck Use default build command and change the makecommand to make -f hello.mak or whatever command you need.

Upvotes: 2

Nelson Teixeira
Nelson Teixeira

Reputation: 6590

You can create a external tool which runs any command line command you can think of. Just click in arrow near the External tools icon and select "External Tools Configurations".

Upvotes: 0

user2917778
user2917778

Reputation:

In any project you have main file usually "makefile." You must edit this file.

if you look through the main makefile you'll find something like this:

all: #usually with dependencies.

This is a make rule, to make your own just add it in the same way:

test: #some command or dependency.

Then when you do make test it will do what you asked it to.

check this out for some more examples and better understanding on makefile rules.
GNU Make

here's some stuff for making new files in eclipse if you haven't seen it yet.
makefile in Eclipse

Upvotes: 0

Related Questions