Multiple include paths (-I) for g++ in Eclipse and MinGW - c++

I am using Eclipse Luna in a Windows environment to write programs in C++. I compile with MinGW. I am also using OpenCV and libxml2.
My programs get compiled with these include paths:
g++ "-IC:\\MinGW\\include\\libxml2" ...
However, I need include paths for libxml, so what I want is:
g++ "-IC:\\MinGW\\include\\ibxml2" "-IC:\\opencv\\build\\include"
I tried to set this up under "project | Propterities | Tool Settings | GCC C++ Compiler" in the project properties:
-I"C:\opencv\build\include" -I"C:\MinGW\include\libxml2" -O0 -g3 -Wall -c -fmessage-length=0 -v
However, it only puts the first one in the actual compile command, according to the console.
It does work sometimes, though:
If I "Clean" the project and the build it, it will build without errors and even run from Windows Explorer or a prompt.
If I try to Run or Debug it from Eclipse, it will fail and have the problems described above.
If I "Clean" it and Run or Debug it, it will run fine in the Debug perspective, but will terminate without warning.

Related

Why does a 2-stage command-line build with clang not generate a dSYM directory?

I have a simple project I want to debug want to produce dSYM folder with debugging symbols.
Running:
clang++ -std=c++14 -stdlib=libc++ -g -o Lazy Lazy.cpp
Creates Lazy.dSYM as I expect.
However:
clang++ -std=c++14 -stdlib=libc++ -g -c Lazy.cpp
clang++ -stdlib=libc++ -g -o Lazy Lazy.o
Does not create Lazy.dSYM (It seems that the symbols are embedded in the binary).
Sadly the 2-step build is what my modified makefile does. How can I generate Lazy.dSYM from a 2-stage compile-and-link build?
I don't need a dSYM directory, just debugging symbols, but would like to understand when and why it is created.
The creation of the .dSYM bundle is done by a tool called dsymutil. When Apple added support for DWARF debugging information, they decided to separate "executable linking" from "debug information linking". As such, the debug information linking is not done by the normal linker, it's done by dsymutil.
As a convenience, when you build a program all in one step, the compiler invokes dsymutil on your behalf. That's because it knows it has all of the inputs. If you add the -v (a.k.a. --verbose) option to the compile command, you will see the invocation of dsymutil as the last step it does.
In other cases, though, it doesn't do that. It leaves the debug information linking step for the user to do manually. You can do it by simply issuing the command:
dsymutil <your_program>
Here's an article by an Apple engineer who helped design and implement Apple's support for DWARF explaining their thinking. He also answered a question here on Stack Overflow about this stuff.

Problems in setting up GLFW in CodeBlocks

I downloaded GLFW 3.1.1 and followed a tutorial telling me to:
Drop glfw3.h into MinGW's include folder
Drop the contents of lib-mingw in the downloaded file into MinGW's lib folder
Run the test program that comes with GLFW
After doing this I kept running into an error that stopped me from even starting a new GLFW project as the wizard kept looking for glfw.h and glfw.dll when they're now glfw3.h and glf3.dll I edited the wizard and was finally able to get the new project open.
After that, I clicked build and run and the compiler asked if I was sure. When I clicked yes it continually asked me if I wanted to build and run. The debugger just gives me this and I'm not sure what I set up wrong.
-------------- Build: Debug in 112311 (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Wall -g -I"C:\Program Files\MinGW\include" -c "C:\Users\User\Desktop\Folders\C++ Files\112311\main.cpp" -o obj\Debug\main.o
Execution of 'mingw32-g++.exe -Wall -g -I"C:\Program Files\MinGW\include" -c "C:\Users\User\Desktop\Folders\C++ Files\112311\main.cpp" -o obj\Debug\main.o' in 'C:\Users\User\Desktop\Folders\C++ Files\112311' failed.
-------------- Run: Debug in 112311 (compiler: GNU GCC Compiler)---------------
Checking for existence: C:\Users\User\Desktop\Folders\C++ Files\112311\bin\Debug\112311.exe
i
You should avoid using the wizard for GLFW projects because it's for an outdated version of GLFW.
You should create a console application then go to Project->Build Options. Go to the Linker settings tab then add glfw3, opengl32 and gdi32, then click OK.
You can now test if it worked by copying the sample code on the GLFW website's documentation page and pasting it in main.cpp, replacing everything and running the program.

Compile XCode 5 project with custom flags

I have a cpp file which I am able to compile from command line using:
clang++ main.cpp -O2 -larmadillo
or by using g++ compiler via
g++ main.cpp -O2 -larmadillo
My question is how can I compile main.cpp in Xcode 5.1.1?
Here is what I tried:
1) Project -> Build Settings -> Other C++ flags -> added '-O2 -larmadillo' there
2) Target -> Build Settings -> Other C++ flags -> added '-O2 -larmadillo' there
Neither helped.
I am new to this linking/compiling magic so I don't know where to go from here.
clang++ and g++ can act as both compilers and as compiler drivers. When you run them from the command line as a compiler driver they internally handle running all the steps for getting an executable, including compiling, assembling, and linking.
But when Xcode is doing the build it instead expects to run clang as a compiler and to handle linking separately. So passing a linker flag in 'Other C++ flags' is basically like doing:
// compile step (no linking)
clang++ main.cpp -O2 -larmadillo -c
// linking step (error, missing library)
clang++ main.o
So what you need to do is change the build settings so that Xcode knows that it needs to link in that library when it gets to the linking step. A quick and dirty way would be to add the linker flag to 'other linker flags' (and to set the library search paths appropriately), but it would be better to edit your target's 'Build Phases" and update the "Link Binary with Libraries" with the appropriate library. You may also need to change the SDK in the target's build settings to 'Current Mac OS', so that Xcode will use whatever libraries you've installed rather than strictly limiting it to what's available in a default OS X install.

not able to make resource compiler to work with Code::Blocks

I use C++ with Code::Blocks. I like Code::Block, but I can't make resource compiler get working... My test setup is very simple.
**in MoviesList.rc file:**
#include "MoviesList.h"
IDR_TEXT1 RCDATA "C:\\_C++\\PROJECTS\\test2\\MoviesList.txt"
**in MoviesList.h file:**
#define IDR_TEXT1 101
**in main()**
{
HRSRC resInfo = ::FindResource(0, MAKEINTRESOURCE(IDR_TEXT1), RT_RCDATA);
return 0;
}
I get this compile error all the time:
x86_64-w64-mingw32-windres.exe -J rc -O coff -i C:\_C__~1\PROJECTS\test2\MOVIES~1.RC -o obj\Debug\MoviesList.res
Execution of 'x86_64-w64-mingw32-windres.exe -J rc -O coff -i C:\_C__~1\PROJECTS\test2\MOVIES~1.RC -o obj\Debug\MoviesList.res' in 'C:\_C++\PROJECTS\test2' failed.
Nothing to be done (all items are up-to-date).
Compiler setup is the following:
C compiler: x86_64-w64-mingw32-gcc.exe
C++ compiler: x86_64-w64-mingw32-g++.exe
Linker for dynamic libs: x86_64-w64-mingw32-g++.exe
Linker for static libs : x86_64-w64-mingw32-ar.exe
Resource compiler: x86_64-w64-mingw32-windres.exe
Make program: mingw32-make.exe
When I go to project's Properties and then to Build Targets I see that main.cpp and MoviesList.rc are checked, which should be correct... I have Mingw version 4.8.1 and Code::Blocks version is 12.11. All things including Boost work fine, except for the resource compiler.
UPDATE
After changing from x86_64-w64-mingw32-windres.exe to windres.exe the build has produce no errors.
There is no x86_64-w64-mingw32-windres.exe in MinGW/bin, just windres.exe.... I
Entry for the resource compiler has been incorrect.
Code::Blocks is an IDE that invokes the compiler, linker and other tools like the resource compiler. The output of these tools is catched and displayed in the output window.
When you don't get any output from one of these tools you should take the build log and start the tools with the parameter you found in the build log. This might help to isolate the problem.
Additionally you could change the parameters. e.g tell the compiler to stop after preprocessing to look at the preprocessed output. Similar options may exist for the resorce compiler.

Configure Eclipse CDT to use g++

I have cygwin installed, and I want to use Eclipse with CDT for development under Windows 7. However, I get following error:
**** Build of configuration Default for project hello_cpp ****
make all
g++ -O2 -g -Wall -fmessage-length=0 -c -o hello_cpp.o hello_cpp.cpp
process_begin: CreateProcess(C:\cygwin\bin\g++.exe, g++ -O2 -g -Wall -fmessage-length=0 -c -o hello_cpp.o hello_cpp.cpp, ...) failed.
make (e=5): Access denied.
make: *** [hello_cpp.o] Error 5
**** Build Finished ****
I'm able to use g++ as standalone compiler.
cygwin /bin folder is
added to path.
After googling I found out that C:\cygwin\bin\g++.exe is a cygwin symbolic link and Windows doesn't understand it and I need to point to the g++-3 location directly. How do I do it?
I think you've done something wrong and need to start over again. Just installed Cygwin and Eclipse CDT (Indigo) on my Windows 7 and all works fine and auto-magicaly for me.
Here's what I did and I think you need to do:
Get the latest Cygwin (yes, get it again! get rid of the old one just to be sure)
During the installation make sure to select gcc, gcc-g++ and make (I additionally installed couple of other things like gcc4, w32api but it's optional)
Start Cygwin terminal to init all configuration files, etc. See if g++ executes and close the terminal.
Add C:\cygwin\bin (or wherever else you installed it) to your Environment PATH variable
Get Eclipse CDT, extract it somewhere and start it up.
Go to File -> New Project -> C++ Project and select Hello World C++ Project. You should see the Cygwin GCC in the Toolchains list.
Create the Project, build and run it!
Done!
Build output:
**** Build of configuration Debug for project TestApp ****
make all
Building file: ../src/TestApp.cpp
Invoking: Cygwin C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/TestApp.d" -MT"src/TestApp.d" -o "src/TestApp.o" "../src/TestApp.cpp"
Finished building: ../src/TestApp.cpp
Building target: TestApp.exe
Invoking: Cygwin C++ Linker
g++ -o "TestApp.exe" ./src/TestApp.o
Finished building target: TestApp.exe
**** Build Finished ****
You can go to
Project Properties Page > C / C++ Build > Settings > Tool Settings
And change the command as you want. Documentation here.
Refer this link, it shows how to setup eclipse for native development with ease. everything is done in eclipse except setting environment variables.