Set up SFML with Code::Blocks on windows 8 - c++

I had Code::Blocks working on my other Windows 8 computer using the GNU GCC compiler, but when I copied and pasted everything exactly the way it was into my other Windows 8 computer, my projects stopped working. Currently, it throws this error:
mingw32-g++.exe -LC:\Matthew\Documents\SFML-1.6\lib -o bin\Debug\Game.exe obj\Debug\Main.o -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -static-libgcc-static-libstdc++ -lsfml-graphics-s-d -lsfml-window-s-d -lsfml-system-s-d -static-libgcc-static-libstdc++
mingw32-g++.exe: error: unrecognized command line option '-static-libgcc-static-libstdc++'
mingw32-g++.exe: error: unrecognized command line option '-static-libgcc-static-libstdc++'
I looked up the problem and found one place recommending that I remove whatever is listed as an unrecognized command from my linker settings, but when I do that it says that it "cannot find" any of the other things I have in my linker. Is there an easy solution to this problem?

It looks like you have two compiler switches concatenated together when they should be separated with a whitespace:
-static-libgcc-static-libstdc++
Try modifying the linking command to:
g++.exe -static-libgcc -static-libstdc++ -LC:\Matthew\Documents\SFML-1.6\lib -o bin\Debug\Game.exe obj\Debug\Main.o -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lsfml-graphics-s-d -lsfml-window-s-d -lsfml-system-s-d

Related

C++ file compiling: -L and -I arguments don't work for boost library

There are similar questions but their answers did not work for my issue.
I have a c++ program with #include <boost/test/unit_test.hpp> on top (among other includes).
To compile correctly, if I understood, I should do the command:
g++ -g -L/path_to_boost_lib -lboost_lib myprog.cpp -o myprog.exe
If i do a locate, I get /usr/lib/x86_64-linux-gnu/libboost_unit_test_framework.so.
Hence I edited my call to g++ by doing:
g++ -g -L/usr/lib/x86_64-linux-gnu -lboost_unit_test_framework myprog.cpp -o myprog.exe
But I still get errors of the type undefined reference to boost::unit_test.
I also tried the option -I/usr/include/ which contains the boost folder, without success.
It's because of the order. The GCC linker goes through the artifacts left-to-right, and every unknown symbol it encounters in an object file must be resolved by an artifact occurring afterwards.
The right command is thus:
g++ -g myprog.cpp -L/usr/lib/x86_64-linux-gnu -lboost_unit_test_framework -o myprog.exe
See this answer for a more thorough explanation.
I suggest using a build tool like CMake that takes care of such low-level details for you.

Cygwin+Eclipse: How does one hide a console window in n OpengGL based program by without getting unrecognized emulation mode error?

I am using a new install of cygwin with glut32 libraries on a Windows 7 64-bit machine. I am trying to put together a test program in C++ using the Eclipse IDE. Standard terminal programs and a test GLUT32 program build and run as expected. I am trying to hide the console window on a release build of my test program.
I attempted to use the -mwindows flag in the linker step to suppress the console window, but I get the following:
11:15:04 **** Incremental Build of configuration Release for project Test ****
make all
Building file: ../src/Test.cpp
Invoking: Cygwin C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/Test.d" -MT"src/Test.o" -o "src/Test.o" "../src/Test.cpp"
Finished building: ../src/Test.cpp
Building target: Test.exe
Invoking: Cygwin C++ Linker
g++ -L"C:\cygwin\lib" -Xlinker -mwindows -shared -o "Test.exe" ./src/Test.o -lglut32 -lglu32 -lopengl32
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: unrecognised emulation mode: windows
Supported emulations: i386pep i386pe
collect2: error: ld returned 1 exit status
make: *** [makefile:47: Test.exe] Error 1
11:15:05 Build Finished (took 376ms)
I think the supported emulation statement might be a hint. Am I somehow using the wrong compiler? How do a build a finished program without having a console windows pop up in the background?
I can't explain why, but the problem is solved when I use the -mwindows flag in the compilation step as opposed to the linking step. Program builds with no problems and runs without the console.

MINGW, Code::Blocks - No such file or directory error when compiling c++

When I try to compile C++ programm in Code::blocks it gives me this error:
-------------- Build: Debug in elcounter (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Weffc++ -Wall -std=c++14 -fexceptions -Weffc++ -std=c++14 -g -I"C:\Users\Zahir\Box Sync\CPP projects\September_2k16\elcounter\" -c "C:\Users\Zahir\Box Sync\CPP projects\September_2k16\elcounter\main.cpp" -o obj\Debug\main.o
mingw32-g++.exe: error: Sync\CPP: No such file or directory
mingw32-g++.exe: error: projects\September_2k16\elcounter\main.cpp -o obj\Debug\main.o: No such file or directory
mingw32-g++.exe: fatal error: no input files
I am using MinGW g++ compiler.
Just for a test, I tried to compile simple "Hello, world" file and it gave me the same error.
Compiled the same "Hello, world" file in a command line using
"g++ test.cpp -o hello.exe" and in worked just fine, so I believe the compiler is installed correctly.
The error seems to be related to spaces in a file path.
C:\Users\Zahir\Box Sync\CPP projects\September_2k16\elcounter\
mingw32-g++.exe: error: Sync\CPP: No such file or directory
mingw32-g++.exe: error: projects\September_2k16\elcounter\main.cpp -o obj\Debug\main.o: No such file or directory
Might be a problem with a build system in Code::blocks? I tried to copy the command code::blocks using to a command line and it gave the same error. (mingw32-g++.exe -Weffc++ -Wall etc.)
EDIT: I don't want to change file path because "Box Sync" is used by the same name app that synchronizes file with a cloud.(box.com) The app doesn't support changing the main folders name and I'd prefer the project files stay synchronized.
Looks like you need to remove all spaces from file and folder names in your project.
In your case it's the 'CPP projects' folder and 'box sync'

Understanding LD under MSYS2

I'm trying to compile the simavr project from https://github.com/buserror/simavr on Windows 10 using MSYS2 and mingw-w64.
After editing the makefiles to enable the MSYS clauses (Which are commented out by default), and changing the order of 2 include files, I can get the project to compile. I do however encounter an error in the linking step.
The output is
C:/Programs/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/5.3.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lsimavr
Editing the makefile to print the ${LDFLAGS}, yield the following.
-L/lib -L/local/lib -L/c/Users/University/GitHub/simavr/simavr/../simavr/obj-i686-w64-mingw32 -lsimavr -lelf -lws2_32
Looking in the folder "obj-i686-w64-mingw32" mentioned in the build script, the file "libsimavr.a" is present. If I copy the file to the msys lib folder the linking step works fine.
The folder structure of the project is as follows:
simavr root (Where i run the makefile from, located in /c/Users/University/GitHub)
simavr
obj-i686-w64-mingw32
As far as I can tell, LD should be able to link properly without me copying the file manually. What am I missing here?
Edit:
The final command before the linker error.
cc -MMD -Werror -O2 -Wall -g -I/usr/local/include -DNO_COLOR -o obj-i686-w64-mingw32/run_avr.elf obj-i686-w64-mingw32/run_avr.o -L/lib -L/local/lib -L/c/Users/University/GitHub/simavr/simavr/../simavr/obj-i686-w64-mingw32 -lsimavr -lelf -lws2_32
Edit 2:
Cleaning the include paths of MSYS folders:
cc -MMD -Werror -O2 -Wall -g -DNO_COLOR -o obj-i686-w64-mingw32/run_avr.elf obj-i686-w64-mingw32/run_avr.o -L/c/Users/University/GitHub/simavr/simavr/../simavr/obj-i686-w64-mingw32 -lsimavr -lelf -lws2_32
C:/Programs/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/5.3.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lsimavr
Passing CC=gcc to make:
gcc -MMD -Werror -O2 -Wall -g -DNO_COLOR -o obj-i686-w64-mingw32/run_avr.elf obj-i686-w64-mingw32/run_avr.o -L/c/Users/University/GitHub/simavr/simavr/../simavr/obj-i686-w64-mingw32 -lsimavr -lelf -lws2_32
C:/Programs/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/5.3.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lsimavr
Edit 3:
Output of the find command:
$ find /c/Users/University/GitHub/simavr -name 'libsimavr.a'
/c/Users/University/GitHub/simavr/simavr/obj-i686-w64-mingw32/libsimavr.a
Note that previous entries have been made using the git bash prompt, not the one from msys2. However, running the same commands in the msys2 prompt or the mingw prompt from msys2 yields the same results.
Using mingw-w64 toolchain to build project you MUST remove from CFLAGS/CXXFLAGS/CPPFLAGS all paths with /usr, /local, /lib, /include as this paths can contain headers and libs from MSYS2 itself. Second, try pass "CC=gcc" to makefile.

g++ won't play nice with wx-config

I'm on windows using mingw and when i use the following to try and compile my wxWidgets code
g++ main.cpp `wx-config --libs` `wx-config --cxxflags`
I get the following error
g++: `wx-config: No such file or directory
g++: `wx-config: No such file or directory
cc1plus.exe: error: unrecognized command line option "-flibs`"
cc1plus.exe: error: unrecognized command line option "-fcxxflags`"
And I cannot figure out what to do to make g++ play nice with wx-config
Please help, thanks.
What shell are you using? Back quotes don't work on the Windows command prompt. You may need to use msys and bash.