Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

First C programm - need help with eclipse

Tags:

c

eclipse

I have install the C/C++ CDT Version of Eclipse. After making a HelloWorld.c file and get the code in there I get an error of "Launch failed. Binary not found".

I found in google that my Eclipse miss the compiler and I install MinGW on my computer and add the path to env variables (tested it with "gcc -v" in cmd and succeded).

1) I can build now, but have no idea how to make a MAKEFILE. - I Read 10 tutorials but don't understand it - ideas?

2) I can build, but not run, I get "Launch failed. Binary not found" - ideas?


Found the error: I never maked a ".c" file -.- after renaming it - works fine.

like image 529
PassionateDeveloper Avatar asked Jul 15 '26 11:07

PassionateDeveloper


1 Answers

  1. Revised answer: If you want to avoid writing a real makefile, you can write something like this:

    all:
        gcc *.c -o runme.exe
    
  2. You need to specify the binary which gcc outputs (gcc [..] -o <this one>) in the run settings (in the previous example, it should point to runme.exe). Go to Run->Run Configurations, and under C/C++ Application browse and look for runme.exe.

I would, however, strongly advise you to seriously learn about makefile. The beauty of makefiles is that you can use very little features at first and use more and more as you go on (as you saw, writing a "dummy" file was very quick). At first I suggest you write something a bit more "clever" than what I gave you above. Here's a nice tutorial and an example:

all: hello

hello: main.o factorial.o hello.o
    g++ main.o factorial.o hello.o -o hello

main.o: main.cpp
    g++ -c main.cpp

factorial.o: factorial.cpp
    g++ -c factorial.cpp

hello.o: hello.cpp
    g++ -c hello.cpp

clean:
    rm -rf *o hello

all is what compiles at default. What comes before the : are rule names and after it are the dependencies. i.e, to compile all you need to compile hello (though only if it's been updated), and so forth. the line below the rule is the command to compile. I hope this helps. Please read the tutorial, Makefiles are important.

like image 75
Amir Rachum Avatar answered Jul 17 '26 16:07

Amir Rachum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!