How to setup a makefile in eclipse (C++)? - c++

I have a project in Eclipse and I want to use my own makefile.
I went to
project -> properties -> C/C++ Build
and unchecked "Generate Makfiles Automatically". I have a makefile named Makefile in the project base dir which just contains:
all:
g++ *.cpp -o Simulator.exe
When I try to build, I get the following error:
Build of configuration MinGW GCC for project CacheOptimization
(Cannot run program "make": Launching failed)
How can I fix this and make eclipse compile my code?

You probably don't have MINGW configured properly, and Eclipse can't run "make". This might be useful: Setting up a compiler

Either:
install MSys package which includes make along with other useful tools (recommended),
or look into your project's settings under C/C++ Build and change the build command from make to mingw32-make, which is distributed as a part of MinGW.

Related

Compile a c++ programm.exe without getting the Error: missing .dll while starting [duplicate]

I have been working on a project (a game to be specific) and I feel that I should start over with different libraries. So when doing this I reinstalled Code::Blocks and setup my new libraries and includes.
But as of now Im having a problem starting u[ my new project to test if all of the includes work. This problem is: libstdc++-6.dll was not found. At first i wondered if I could just find this file online, but its nowhere to be found(or at least the many places I have searched...) Soon after, I tried loading up my old project, and the same problem happened again(wierd... ._.) I was thinking its maybe my compiler, so I used my older compiler and it did the same thing! At this moment I held the problem off for tomorrow(which is today)
So my question is: If anyone else had this problem, how would you solve it?
Im using Code::Blocks with MinGW as the compiler on Windows Vista 32 bit.
*****EDIT*****
Here are the Build options in my project. Note that these are the settings in the Project, not the global compiler:
In (project name)->Compiler settings->Otehr options:
(I use // to seperate the commands)
-mthreads//
-fmessage-length=0//
-fexceptions//
-fident//
In (project name)->Compiler settings->#define:
WIN32//
_WINDOWS//
In (project name)->Linker settings->Other linker options:
-static-libstdc++//
-static-libgcc//
-Wl,--enable-auto-image-base//
-Wl,--add-stdcall-alias//
-Wl,--enable-auto-import//
In linker->link libraries i have various links to files with a .a extension, these files include Bullet PHysics, Ogre3D, and SFML
In the search directories i have links to the MinGW/bin, and the MinGW/lib directories, along with other links to different libraries.
My Compiler is MinGW, a GNU GCC compiler for windows 32 bit. and the IDE is Codeblocks. Also note that in Debug and Release settings on the project, there is nothing.
Most of these setings are also pieces that i got from the Ogre3D Application setup tutorial if that is of any help.
If you are using MingW to compile C++ code on Windows, you may like to add the options -static-libgcc and -static-libstdc++ to link the C and C++ standard libraries statically and thus remove the need to carry around any separate copies of those. Version management of libraries is a pain in Windows, so I've found this approach the quickest and cleanest solution to creating Windows binaries.
As far as I know, this is the C++ Runtime Library. So it depends on the compiler you use to create your program (A new version will include some C++0x stuff, an older version will probably not for instance. It depends of the compiler and of its version).
If you use MinGW then you should use the libstdc++-6.dll found into the folder of this compiler. MinGW/bin folder should be the place to search for it on your computer.
If you copy this file in the same directory as your executable, it should be OK.
Simply removing libstdc++-6.dll.a \ libstdc++.dll.a from the mingw directory fixes this.
I tried using the flag -static-libstdc++ but this did not work for me.
I found the solution in: http://ghc.haskell.org/trac/ghc/ticket/4468#
This error also occurred when I compiled with MinGW using gcc with the following options:
-lstdc++ -lm, rather than g++
I did not notice these options, and added: -static-libgcc -static-libstdc++
I still got the error, and finally realized I was using gcc, and changed the compiler to g++ and removed -stdc++ and -lm, and everything linked fine.
(I was using LINK.c rather than LINK.cpp... use make -pn | less to see what everything does!)
I don't know why the previous author was using gcc with -stdc++. I don't see any reason not to use g++ which will link with stdc++ automatically... and as far as I know, provide other benefits (it is the c++ compiler after all).
useful to windows users who use eclipse for c/c++ but run *.exe file and get an error: "missing libstdc++6.dll"
4 ways to solve it
Eclipse ->"Project" -> "Properties" -> "C/C++ Build" -> "Settings" -> "Tool Settings" -> "MinGW C++ Linker" -> "Misscellaneous" -> "Linker flags" (add '-static' to it)
Add '{{the path where your MinGW was installed}}/bin' to current user environment variable - "Path" in Windows, then reboot eclipse, and finally recompile.
Add '{{the path where your MinGW was installed}}/bin' to Windows environment variable - "Path", then reboot eclipse, and finally recompile.
Copy the file "libstdc++-6.dll" to the path where the *.exe file is running, then rerun. (this is not a good way)
Note: the file "libstdc++-6.dll" is in the folder '{{the path where your MinGW was installed}}/bin'
I use Eclipse under Fedora 20 with MinGW for cross compile.
Use these settings and the program won't ask for libstdc++-6.dll any more.
Project type - Cross GCC
Cross Settings
Prefix: x86_64-w64-mingw32-
Path: /usr/bin
Cross GCC Compiler
Command: gcc
All Options:
-I/usr/x86_64-w64-mingw32/sys-root/mingw/include -O3
-Wall -c -fmessage-length=0
Includes: /usr/x86_64-w64-mingw32/sys-root/mingw/include
Cross G++ Compiler
Command: g++
All Options: -I/usr/x86_64-w64-mingw32/sys-root/mingw/include -O3
-Wall -c -fmessage-length=0
Includes: /usr/x86_64-w64-mingw32/sys-root/mingw/include
Cross G++ Linker
Command: g++ -static-libstdc++ -static-libgcc
All Options: -L/usr/x86_64-w64-mingw32/sys-root/mingw/lib -L/usr/x86_64-w64-mingw32/sys-root/mingw/bin
Library search path (-L):
/usr/x86_64-w64-mingw32/sys-root/mingw/lib
/usr/x86_64-w64-mingw32/sys-root/mingw/bin
I just had this issue.. I just added the MinGW\bin directory to the path environment variable, and it solved the issue.
I placed the libstdc++-6.dll file in the same folder where exe file is generated.
You only need to add your "mingw-install-directory"/bin/ to your Path in your System environment variables ... that's it !!
I had same problem. i fixed it. i was using Codeblocks and i save my .cpp file on desktop instead of saving it in Codeblocks file where MinGW is located. So i copied all dll files from MinGW>>bin folder to where my .cpp file was saved.
You can also copy the dll files in the directory of your exe file
I had this problem too. I was compiling in command prompt and used the flag -static.
My command before:
"g++ test.cpp -o test.exe"
and afterwards:
"g++ test.cpp -o test.exe -static"
I had the same problem and I solved it by running the compiled exe as an administrator.

Eclipse doesn't see include files when checking syntax but does when building or running the application

I started with building my project with CMake by using the cmake <folder> -G"Eclipse CDT4 - Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug command (I'm using Ubuntu 14.04). Say the results were written to /home/student/tempFolder/HelloFrameworkApp folder.
The thing is that I have header files needed for he application in /home/student/git/fagot/sw/branches/head/framework/include folder. This is also described in CMakeLists so after I import my project from /home/student/tempFolder/HelloFrameworkApp to Eclipse as existing code as makefile project, it can successfully be built and runs just as expected.
But in the code edit area there are tons of red underlining which makes it clear that Eclipse can't see the include folder I mentioned before. I tried going to Properties -> C/C++ General -> Paths and symbols and adding that include folder to all configurations and languages but it didn't help.
Any suggestions?
CMake creates an Eclipse project for you. Therefore you need to use: Import->General->Existing Project into Workspace.

How to set Eclipse for cmake project?

I have c++ project with cmake, for building it,i wanted to integrate the project in eclipse ide in linux?And i also googled for the same,but didn't get appropriate answers,Please help me with the same.Thank you in advance.Other IDE are also ok,with steps to import the project without ant errors.Thanks for the help in advance.
The cmake4eclipse Eclipse plugin from the Eclipse marketplace is able to create makefiles (or other buildscripts; it is your choice) from your CMakeLists.txt and build your Eclipse project. Once configured, there is no need to manually run cmake -G "Unix Makefiles". Project settings are stored in the .cproject file and taken from your CMakeLists.txt.
It integrates to CDT, so using the plugin, You should be familar with CDT`s project preference pages (which may be confusing).
To have syntax highlighting in CMakeLists.txt, try cmake-editor.
DISCLAIMER: I am the author of cmake4eclipse.
Using CMake you can generate a project for Eclipse and then open it in the IDE. CMake will be called automatically to regenerate project if you make some changes at that level.

How to debug external .cpp files on Eclipse CDT ( C++ )

I have big project in directory "project". I build this project using cmake into another directory "build". For coding I try to use Eclipse, but when I try to import my code into Eclipse ( File->Import->C/C++->Existing Code as Makefile Project ), of course I can import only "build" directory without "project" ( because make file are in "build" and "project" is empty for Eclipse ).
When I run my build in debug mode, I can debug only binary data, because debuger can't seen sources in "project" directory. How I can setup debuger for use sources from "project" directory? Thanks if some one answered!
import your Project (rootdir not build) as MakeFile Project into the Workspace (select GNU Toolschain or Linux GCC). Now open your project properties -> c++ build and select the build folder inside your project.
Now you can compile it and create a new run configuration for debugging.
Greez ZuSe
Edit:
I assume your rootfolder looks like this
cmake/
CmakeList.txt
src/
dep/
../
now you create a folder build
you switch to build and run cmake cmake ../ -flags (no eclipse-project, use default gcc)
After you have done this u can import your rootfolder to eclipse cdt and select root/build as build folder. Where is the problem? Eclipse CDT only wants to now where the makefile is at buildtime (thats why you manually need to select the buildfolder)
You do not need sources in your workspace to debug the application if you built the application on your system - build directory & paths are in your executable debug information.
Make sure you pass -g both to the compiler and linker.
Try command-line GDB - it should find sources as well.
You may setup custom source mapping in the Eclipse CDT debugger when setting up the launch configuration - but I believe this is mostly for cases when sources were moved after you built the application or if you built on another system.
Here is how i do it, step by step. It is a simple cmake project i downloaded from github.
Works like a harm.
imagebam.com http://thumbnails101.imagebam.com/23645/1e5c42236445850.jpg
imagebam.com http://thumbnails101.imagebam.com/23645/64cb47236445860.jpg

Bullet Physics, CMake->CodeBlocks - MinGW: Doesn't find GL/glut.h?

Statistics...
My System: Windows Vista 64 bit
Library: Bullet Physics v2.78
Makefile Generator: CMake
Build system: MinGW command line, MinGW + CodeBlocks
Makefiles were implemented by command line and through CMake-generated Code::Blocks project
In both cases, the build fails near 30%. NOTE: I did have to switch the build executable in the Code::Blocks project from make.exe to mingw32-make.exe
First Failure: Demos\OpenGL\GLDebugFont.cpp -> GL/glut.h: No such file or directory
Second Failure (after commenting out the #include from the first) -> Demos/OpenGL/GlutStuff.h: same error
These failures happen when I build command-line OR through the generated C::B project.
Why can't it find GL/glut.h? "bullet-2.78\Glut\GL\glut.h" exists. Maybe there's a way I can tell it to find glut there?
NOTE: During the CMake makefile generation, CMake did tell me that "You are using the obsolete GLU package, please use OpenGL instead." It continued as normal with the Makefile generation. Maybe I need to define some environment variables? Maybe I need to configure something in Windows that CMake is looking for?
I would add a compiler search path in bullet-2.78/Glut, but Code::Blocks doesn't allow that if you're using a custom makefile (like a CMake-generated one).
UPDATE: I have been able to build the library itself, by building specific targets in the Code::Blocks project. However, I have been unable to build any of the demos or the benchmark test, since they all use OpenGL (and apparently glut.h). I would still like to compile those.