Compile from linux for windows in eclipse - c++

I'm trying to compile my project in eclipse(linux) for windows.
I followed a guide, then I'm able to compile for windows from command line. I tried to create my project using GCC-toolchain and selecting my prefix/directory
Output on the eclipse console is:
Building file: ../src/provagcc2.cpp
Invoking: Cross G++ Compiler
x86_64-w64-mingw32-g++ -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/provagcc2.d" -MT"src/provagcc2.o" -o "src/provagcc2.o" "../src/provagcc2.cpp"
Finished building: ../src/provagcc2.cpp
Building target: provagcc2
Invoking: Cross G++ Linker
x86_64-w64-mingw32-g++ -o "provagcc2" ./src/provagcc2.o
Finished building target: provagcc2
however, it generates a .o file instead of a .exe

-o "provagcc2" looks like you did not specify an extension for the output. There should also be a provagcc2 without extension lying around somewhere as a result. The provagcc2.o file you have found is likely the is the result of compiling. provagcc2.cpp
-o "provagcc2.exe" is what you want on the command line.
To tell Eclipse to name the file correctly, you need to navigate to Project->Properties on the menu. In the Properties dialog that pops up, expand C/C++ Build and select Settings. Select the Build Artifact tab and type exe into the Artifact extension field. Apply and Close and rebuild the project.

Related

Eclipse CDT Cygwin error

i have a problem with eclipse CDT and cygwin, when i try to build a simple hello world project i have this error:
make all
Building file: ../src/test.cpp
Invoking: Cygwin C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/test.d" -MT"src/test.d" -o "src/test.o" "../src/test.cpp"
C:\shell.w32-ix86\make.exe: *** [src/test.o] Error 1
14:37:48 Build Finished (took 178ms)
Cygwin is in the path and commands like 'g++' or 'make' works fine.
Thank in advance for your help.
Follow this tutorial to properly set up cygwin with Eclipse CDI. After completing all the steps, add one more path dependency on: Project Properties -> C/C++ General -> Paths and Symbols -> Includes GNU C++ with the value to : ${CYGWIN_HOME}/usr/i686-pc-cygwin/sys-root/usr/bin. This solved all the issues arising on Eclipse CDT with CYGWIN.

Binary is never build

I can't get the following code to run:
#include <iostream>
int main()
{
std::cout << "Hello World" << std::endl;
return 0;
}
There are no compile errors.
The build output:
18:18:58 **** Incremental Build of configuration Debug for project First Project ****
Info: Internal Builder is used for build
g++ "-Ic:\\mingw\\lib\\gcc\\mingw32\\4.8.1\\include\\c++" "-Ic:\\mingw\\lib\\gcc\\mingw32\\4.8.1\\include\\c++\\mingw32" "-Ic:\\mingw\\lib\\gcc\\mingw32\\4.8.1\\include\\c++\\backward" "-Ic:\\mingw\\lib\\gcc\\mingw32\\4.8.1\\include" "-Ic:\\mingw\\include" "-Ic:\\mingw\\lib\\gcc\\mingw32\\4.8.1\\include-fixed" -O0 -g3 -Wall -c -fmessage-length=0 -o Hello.o "..\\Hello.cpp"
18:18:58 Build Finished (took 166ms)
I get the dreaded "Launch failed. Binary not found." dialog. I've been over google for hours now, but nothing works.
In my project folder, a debug or release folder are created (depending on what I set it to) but it's always empty. No 'binaries' folder is created, as some posts mentioned it should.
No proposed solution worked, and disabling the antivirus didn't solve it.
How do I fix this? Thank you.
EDIT
Eclipse Version Kepler Severive Release 1
Build id: 20130919-0819
CDT Version: 8.3.0.201402142303
I'm using MinGW
EDIT2
Changing the "current builder" in properties>c/c++ build>tool chain editor from CDT internal builder to Gnu Make Builder does generate a makefile.
Output:
13:57:41 ** Auto Build of configuration Debug for project First Project **
make all
Building file: ../Hello.cpp
Invoking: GCC C++ Compiler
g++ -I"c:\mingw\lib\gcc\mingw32\4.8.1\include\c++" - I"c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\mingw32" - I"c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\backward" -I"c:\mingw\lib\gcc\mingw32\4.8.1\include" -I"c:\mingw\include" -I"c:\mingw\lib\gcc\mingw32\4.8.1\include-fixed" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"Hello.d" -MT"Hello.d" -o "Hello.o" "../Hello.cpp"
make: * [Hello.o] Error 1
13:57:42 Build Finished (took 881ms)
Which compiler are you using? It appears that you are only compiling your code, not linking it too. You must build and link in order for it to work.
The -c flag only compiles the source file. It doesn't link with the object file into an executable. Add this:
g++ -o "..\\Hello.exe" "..\\Hello.o" && "..\\Hello.exe"
Just remove -c flag from your compile line and change -o Hello.o to -o Hello.exe (guess you use Windows).

Still getting "Binary Not Found" error even after building (Eclipse OSX Mtn. Lion)

I recently installed Eclipse for C/C++ on my mac. Whether I'm compiling C or C++, I still get every time: Binary Not Found even after I've built with no errors. I have Xcode installed with the Command Line Tools and GCC and G++ work perfectly fine from the mac terminal. Compiling is fine, at least to my knowledge, in Eclipse but running it won't work. The executable that eclipse creates, however, under the Debug folder of my project, also runs fine. Here's what Eclipse puts in the console when building
`make all
Building file: ../test1.c
Invoking: Cross GCC Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"test1.d" -MT"test1.d" -o "test1.o" "../test1.c"
Finished building: ../test1.c
Building target: test1
Invoking: Cross GCC Linker
gcc -o "test1" ./test1.o
Finished building target: test1`
I have my artifact set to executable and have tried everything I can think of.
Thanks in advance!
Preferences > c/c++ > new c/c++ project wizard
click on Cross GCC or MacOSX GCC then click on make toolchain(s) preferred

problem building cpp project in eclipse

I have installed minGW and msys. In eclipse CDT I created c++ project that uses cross gcc toolchain.
Eclipse created make file which I can use through command line, so if I run make all project is correctly compiled, but if I use eclipse to build, it fails with following message
**** Build of configuration Debug for project cpp ****
make all
Building file: ../src/main.cpp
Invoking: Cross G++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/main.d" -MT"src/main.d" -o "src/main.o" "../src/main.cpp"
make: *** [src/main.o] Error 1
**** Build Finished ****
I have chosen wrong toolchain in project, changed to mingw gcc and now it works

Having trouble building c++ project in Eclipse CDT in OS X for a silly reason

I'm trying to build a very simple c++ program in eclipse and I'm getting a very silly error:
**** Internal Builder is used for build ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -oMyFirst.o ../MyFirst.cpp
g++ -oLinkedLists MyFirst.o
ld: unknown option: -oLinkedLists
collect2: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 403 ms.
The problem is that g++ in osx does not like the -o flag in the "g++ -oLinkedLists MyFirst.o" command right next to the executable file name... Does anybody know how to either configure g++ to accept that or how to configure the builder in eclipse such that there's a space between the -o flag and and file name like this: "g++ -o LinkedLists MyFirst.o"?
Thx in advance!
To further clarify this issue, the solution isn't necessarily to use the MacOSX gcc toolchain. The problem is with the command line pattern for the linker in the toolchain. All you need to do to fix the problem is to edit the command line pattern to ensure there are spaces between each term.
By default, the command line pattern for the Linux gcc linker is something like:
${COMMAND} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT}${INPUTS}
Note the lack of spaces between ${OUTPUT_PREFIX} and ${OUTPUT}. This is the crux of the problem. Simply add a space between those two terms, and your problem is solved.
Mark actually pointed me in the right direction but what I had to do to make it work was to go to:
Project >> Properties >> C/C++ Build >> Tool Chain Editor
I then changed the "Current toolchanin" select box to "MacOSX gcc" and that fixed it :)
I use eclipse CDT 3.5 on OSX 10.5 and it works -
**** Internal Builder is used for build ****
g++ -I/opt/local/include -O0 -g3 -Wall -c -fmessage-length=0 -osrc/tet.o ../src/tet.cpp
g++ -o tet src/tet.o
Build complete for project tet
I get a space in the link line for my executable tet
I am using the default settings
In settings->C/C++ Build->Settings->Mac OSX C++ linker the comand line pattern is
${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}