First C programm - need help with eclipse - c

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.

Revised answer: If you want to avoid writing a real makefile, you can write something like this:
all:
gcc *.c -o runme.exe
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.

Add the directory that gcc resides in (C:\MinGW\bin or whatever) to your PATH environment variable and restart Eclipse (important!). This is the process in XP: http://vlaurie.com/computers2/Articles/environment.htm. That should sort it out.

1 I suggest you to take a look at this:
http://www-scf.usc.edu/~csci410/handouts/make.pdf
It's a basic gmake tutorial and should be enough to get you started. But right now, for single file project, I suggest you to just skip creating Makefiles and doing in the command prompt:
gcc -o helloworld.exe helloworld.c
And running your executable in the prompt. You can worry about Makefiles later in your learning curve.
2 How did you setup your project?

Make sure you've got a binary parser selected when you bring up properties for the project. At least in my install, none were checked by default. I needed to check Mach-O 64 parser; you'll need to pick one based on what you're doing. I picked this up from http://www.thexploit.com/tools/os-x-10-6-64-bit-eclipse-cdt-missing-binaries/
I didn't have a binary parser selected, and that seems to mean that CDT can't find anything that it recognizes as a binary. It meant in my case that I just got the "Launch failed. Binary not found" message, even though I specified the exact binary, including a fully-qualified path, in the run/debug configurations.
This has nothing to do with builds, just running/debugging. If you're having a problem building, this probably is irrelevant.

Related

Link a makefile for using SDL librarie

I'm learning using the SDL librarie, with a french site.
This is the tuto :
"There may be some of you who have gotten into the habit of compiling by hand under Linux using a Makefile (file controlling compilation).
If this is your case, I invite you to download a Makefile which you can use to compile SDL projects.
The only thing a little special is the addition of the SDL library for the linker (LDFLAGS). You will have to download the Linux version of the SDL and install it in your compiler folder"
I've found my gcc folder in /usr/bin/gcc , but when I want to move the makefile to this folder, the error is :
mv: cannot move 'makefile_sdl' to '../usr/bin/makefile_sdl': Permission denied
There it is my make file, maybe something's wrong or missing (i'm a beginner ahah)
CPP=gcc #compiler command
CFLAGS=-O3 #Option d'optimisation du programme
LDFLAGS=-lSDL -lSDL_mixer #Linker
EXEC=nomProgramme #Nom du programme à modifier
all: ${EXEC}
${EXEC}: ${EXEC}.o
${CPP} $(CFLAGS) -o ${EXEC} ${EXEC}.o ${LDFLAGS}
${EXEC}.o: ${EXEC}.c
${CPP} $(CFLAGS) -o ${EXEC}.o -c ${EXEC}.c
You don't need to (and shouldn't) move the makefile to /usr/bin.
You can put it anywhere, but things will be easier if it's in the same directory as your source code (nomProgramme.c).
You need to name your Makefile Makefile. Case sensitive, make sure to check for spelling errors, etc. You also need to be in the same directory as Makefile when you run make.
You should also just run make without any specified targets. It will automatically build the all target, which will build your program into an executable called nomProgramme.
You'll also need to install libsdl-mixer1.2-dev (sudo apt-get install libsdl-mixer1.2-dev and change EXEC=main back to EXEC=nomProgramme.
Here's a link to the GNU make documentation. It gives a quick overview and then a very detailed explanation of everything you can do with GNU make: https://www.gnu.org/software/make/manual/make.html
to answer the OPs question:
the directory /usr/bin is not writable via user (like yourself).
However, executing a command line that is prefixed with sudo (giving you 'root' privileges) will enable you to write on that directory.
However, /usr/bin is intended for executable files and Makefile_sdl is NOT an executable file
Suggest saving that file 'somewhere' Then when you want to use that makefile, to copy it to the directory where your current project is located (I.E. the directory in which you want to run make
However, Makefile_sdl is not one of the standard file names recognized by make so must run make via:
make -f Makefile_sdl

gcc and liboauth - linker can't find oauth.h

I'm trying to use liboauth with a C program, using gcc as my compiler, and no matter what I've tried I keep getting the error "ld: library not found for -loauth" and "clang: error: linker command failed with exit code 1".
I'm including the header via "#include <oauth.h>", and my most-recent call to gcc looked like this:
gcc -Wall -lcurl -loauth -I /usr/local/include -v -o api api.c
Now, oauth.h does exist in /usr/local/include, and there are a handful of liboauth files (including liboauth.a) located in /usr/local/bin, which I'm assuming were placed there when I ran the install. I will admit that I'm not very familiar with gcc and compiling non-trivial C programs, but I was able to get libcurl working on a fresh download in just a few minutes. I just can't figure out what's going on with liboauth.
Thanks in advance
If you are sure liboauth's located in /usr/local/bin use
gcc -Wall -L/usr/local/bin -I /usr/local/include -v -o api api.c -lcurl -loauth
It'd also be better to place libraries in the end of the command as there is some important stuff with them (they may depend on each other, etc).
By the way, it's pretty strange your libraries are in /usr/local/bin as libraries are almost always stored in some path like /usr/*/lib.

OpenCV - C library is not working in my Ubuntu11.10

Resently I'm installed Opencv in my machine. Its working in python well(I just checked it by some eg programs). But due to the lack of tutorials in python I decided to move to c. I just run an Hello world program from http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/
while compiling I got the following error
hello-world.c:4:16: fatal error: cv.h: No such file or directory
compilation terminated.
I'm new in opencv
Qn : Could you please report what may be the problem - and how I run my helloworld program in c?
Your compiler cannot find your cv.h include file. If you installed from your package manager, it is probably in /usr/include/opencv/. You need to add that your include search path. If you are compiling from the command line use -I to specify additional include directories. It will be something like -
gcc -I /usr/include/opencv/ -o helloworld helloworld.c
If you are using Eclipse,
Right click on the project and select properties.
Select C/C++ General -> Path and Symbols.
Select Includes tab.
In Languages list, select 'GNU C' or 'GNU C++' depending on which you are using.
Press 'Add...' button and add /usr/include/opencv/
Save and rebuild.
You need to show compiler path to cv.h file. The quick way to find it is to do (on Ubuntu):
find /usr -name "cv.h"
/usr/local/include/opencv/cv.h
Just add this to the compiler:
gcc -I/usr/local/include/opencv -o helloworld helloworld.c
Since you asking this question your compiler might also have problems linking your program to opencv libraries. Just do the same thing only for library files:
find /usr -iname "libopencv*"
/usr/local/lib/libopencv_flann.so
...
add this folder the same way and specify libraries you want to use:
gcc helloworld.c -I/usr/local/include/opencv -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -o helloworld
that should probably compile. There is a also a short cut you can take and instead of all that steps just use the following command
gcc helloworld.c `pkg-config --cflags --libs opencv` -o helloworld
that should take care of all the work of locating required files for you and let you focus on the fun coding part.
maybe you just installed the opencv package.
But, as you want to use opencv in your C program, you may also install the package named just like opencv-devel. If you haven't, install it and than use it as #iagreen said.
Best wishes to you.

Correct syntax checkin with external makefile

I've made a Makefile project (New -> C Project -> Makefile project). And it's correctly compiles.
But syntax checker is not working properly because of Eclipse doesn't import some important options from makefiles. -I (header folders) for example.
How to solve this problem?
Eclipse uses build output generated by your makefiles to parse compilation flags, inclusion paths, predefined macros, etc. It expects that your build system echoes each command it executes.
That is, it will not work, if the output of make looks like this:
[CC] foo.o
[CC] bar.o
[LD] baz
Make sure, that it prints raw commands, like:
gcc -Ipath/to/include -DFOO=1 -O2 ... -o foo.o -c foo.c
gcc -Ipath/to/include ... -o bar.o -c bar.c
ld foo.o bar.o -o baz
Some build tools provide an option to enable a verbose mode (like make V=1). However, handwritten makefiles are usually OK, because Make echoes executed commands by default.
In this case Eclipse will be able to recognize build options (like path/to/include or FOO=1) and use them to setup C/C++ indexer.
Related project settings
Configuring the project:
In C/C++ Build -> Discovery Options check these entries:
Automate discovery of paths and symbols
Discovery profile: GCC per file scanner info profile
Enable build output scanner info discovery
After that you need to perform a fresh build from inside Eclipse (Clean Project, then Build Project), so that it will see a complete build log.
This feature is rather fragile, and gets broken sometimes... Usually it helps to flush the index using Project -> Index -> Rebuild.

Eclipse can't run my Makefile

I'm writing a C project in Eclipse and while trying to run it I get the following error message:
(Cannot run program "make": Launching failed)
My Makefile is:
all : GenericHashTable.o TableErrorHandle.o
gcc -Wall GenericHashTable.o TableErrorHandle.o -o all
GenericHashTable.o : GenericHashTable.c GenericHashTable.h TableErrorHandle.h
gcc -Wall -c GenericHashTable.c -o GenericHashTable.o
TableErrorHandle.o : TableErrorHandle.c TableErrorHandle.h
gcc -Wall -c TableErrorHandle.c -o TableErrorHandle.o
clean :
rm all *.
Is the formatting broken in your makefile or in your question? Commands on the line below the target & dependencies. Does this makefile work from the command line?
Assuming the makefile is correct check the obvious things such as ensuring Eclipse can see your toolchain. Perhaps it can't even find the make command or you haven't set it from preferences.
Also the CDT offers a managed makefile and a standard (manual) makefile. The managed means Eclipse will create the makefile for you. The standard makefile is a makefile you are responsible for writing. Perhaps if your project is simple you should use the managed makefile to save yourself the hassle of writing one.
You can try the internal builder from eclipse:
Project->Properties->C/C++ Build
There (in the top level of C/C++ Build) you find Builder Settings->Builder Type which you set to Internal Builder. This way CDT does not require an external make command.
Either use the internal builder as "Turbo J" already suggested or make shure 'make' is in your PATH.
You can set the PATH for the build process in the Project-Properties in 'C/C++ Build -> Environment' - click "Select..", choose PATH and then change it by adding the correct path for the 'make' command.
This way you can also set the PATH of your compiler - that may be necessary if you use the Internal Builder.

Resources