Code::Blocks linking not working, on prompt it does - c++

I'm having quite a bit of trouble linking a test project of FLTK I'm doing on Code::Blocks, Windows 7.
After spending quite a lot of time understanding how to put the libraries in the correct order, I managed to get the project nearly done. However there's still a linking problem:
mingw32-g++.exe -Wall -fexceptions -IC:\Users\Svalorzen\Documents\Projects\fltk-1.3.0 -mwindows -DWIN32 -DUSE_OPENGL32 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -c C:\Users\Svalorzen\Documents\Projects\test\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -o bin\Debug\test.exe obj\Debug\main.o -LC:\Users\Svalorzen\Documents\Projects\fltk-1.3.0\lib -mwindows -lfltk -lole32 -luuid -lcomctl32
C:\Users\Svalorzen\Documents\Projects\fltk-1.3.0\lib/libfltk.a(Fl_Native_File_Chooser.o):Fl_Native_File_Chooser.cxx:(.text+0x1556): undefined reference to `__chkstk_ms'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 1 seconds)
1 errors, 0 warnings
However, using the same exact script that Code::Blocks shows, executed on command prompt ( or even msys for what matters ), correctly compiles and links everything. The resulting exe also works.
C:\Users\Svalorzen\Documents\Projects\test>mingw32-g++ -Wall -fexceptions -IC:\Users\Svalorzen\Documents\Projects\fltk-1.3.0 -mwindows -DWIN32 -DUSE_OPENGL32 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -c C:\Users\Svalorzen\Documents\Projects\test\main.cpp -o obj\Debug\main.o
C:\Users\Svalorzen\Documents\Projects\test>mingw32-g++ -o bin\Debug\test.exe obj\Debug\main.o -LC:\Users\Svalorzen\Documents\Projects\fltk-1.3.0\lib -mwindows -lfltk -lole32 -luuid -lcomctl32
C:\Users\Svalorzen\Documents\Projects\test>dir bin\Debug\test.exe
Volume in drive C has no label.
Volume Serial Number is 00E8-6659
Directory of C:\Users\Svalorzen\Documents\Projects\test\bin\Debug
10/05/2012 19:01 661.087 test.exe
1 File(s) 661.087 bytes
0 Dir(s) 66.016.849.920 bytes free
The paths in the instruction are all absolute, so I don't really understand why this is.
What am I doing wrong? What I should check?
EDIT: It turned out that I had a MinGW installation I didn't remember about and Code::Blocks was using that one. I changed it and now everything is fixed.

If your MinGW is up-to-date, then try adding -no-vcproj and -no-dsp and then run mingw32-make confclean.

It turned out that I had a MinGW installation I didn't remember about and Code::Blocks was using that one.
I setup Code::Blocks with the same compiler that created the library and now everything is fine.

Related

Novice: How can I learn how to build GLEW with MinGW? [duplicate]

This question already has answers here:
Building glew on windows with mingw
(8 answers)
Closed 3 years ago.
I'm a daft C/C++ novice using Windows, building with MinGW through console. I have been looking for days on how to build GLEW so that I can statically link it with my incredibly simple SDL+OpenGL program. For static linking, GLEW supposedly requires a special lib apart from lglew32 called lglew32s, and this is what I cannot get my hands on.
I'm trying to learn to use gcc/g++ right now, and to understand the options and the whole preprocess/compile/link thing in general. I'm about 5% there. I found some GLEW building batch file examples around the net, most being pretty old, but even one of them that was new didn't compile lglew32s for me, so I can dynamically link but I can't statically link.
So because I can't find glew32s.lib anywhere online built with anything other than VS, I have to learn to understand what this means and somehow figure out how to compile glew32s with what I've learned from it:
gcc.exe -DGLEW_NO_GLU -O2 -Wall -W -Iinclude -DGLEW_BUILD -o src/glew.o -c src/glew.c
gcc.exe -fno-builtin -fno-stack-protector -shared -Wl,-soname,libglew32.dll -Wl,--out-implib,lib/libglew32.dll.a -o lib/glew32.dll src/glew.o -L/mingw/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32 -nostdlib
ar.exe cr lib/libglew32.a src/glew.o
gcc.exe -DGLEW_NO_GLU -DGLEW_MX -O2 -Wall -W -Iinclude -DGLEW_BUILD -o src/glew.mx.o -c src/glew.c
gcc.exe -fno-builtin -fno-stack-protector -shared -Wl,-soname,libglew32mx.dll -Wl,--out-implib,lib/libglew32mx.dll.a -o lib/glew32mx.dll src/glew.mx.o -L/mingw/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32 -nostdlib
ar.exe cr lib/libglew32mx.a src/glew.mx.o
I have learned to compile my own .cpp and .c projects using gcc/g++ (again I'm barely out of the "hello world" phase in terms of actual code), and also how to dynamically link them to the SDL and GLEW libraries. I understand very well now what this all means:
g++ sdlglew.cpp -o sdlglew -Wall -lmingw32 -lSDL2main -lSDL2 -lglew32 -lopengl32 -I "C:\SDL2-2.0.9\i686-w64-mingw32\include\SDL2" -L "C:\SDL2-2.0.9\i686-w64-mingw32\lib" -mwindows
(My SDL stuff is off in its own directory. GLEW's headers and libs are in MinGW's dir)
I think I need either -DGLEW_STATIC in my command OR #define GLEW_STATIC in my sdlglew.cpp to compile GLEW statically, but those options with lglew32 give me no errors upon compile and fail to start due to the missing glew32.dll. Compiler spits out errors with -static because SDL has not been set up for it yet.
Basically, if you have any resources on understanding what exactly the mentioned compile script is doing per line and how I could build glew32s, I'd be real happy :S I want to understand it, but it really seems like there's no documentation on it for us newbies
Can't you use the Makefile? (It should be included in the MinGW evironment, I think)
In which case I think you should just be able to do something along the lines of:
cd thefolderwithmakefile
make all GLEW_STATIC=1
Then you need to define GLEW_STATIC ( as you said by -DGLEW_STATIC or by #define GLEW_STATIC )when you are building your project files as well.

wxwidget 3.1.2 codeblocks 17.04 error at linking step

OS : windows 10 64 bit
IDE : codeblocks 17.12
Compiler : gcc 7.3
with
wxWidget 3.1.2
i build wxWidget 3.1.2 according to the official guide without changing any defaults
make -f makefile.gcc (make v4.2)
i am using codeblocks wxwidget start script 3.1.X
i have choosen correct option according to the wxWidget build
(Monolithic unicode and debug)
The codeblock generated sample problem is not linking properly
( gives build fail with 0 error 0 warning )
-------------- Clean: Debug in sac (compiler: GNU GCC Compiler)---------------
Cleaned "sac - Debug"
-------------- Build: Debug in sac (compiler: GNU GCC Compiler)---------------
g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -Winvalid-pch -include wx_pch.h -DWX_PRECOMP -Wall -g -IC:\wxWidgets-3.1.2\include -IC:\wxWidgets-3.1.2\lib\gcc_dll\mswu -c C:\Users\MC\Desktop\wxw\sac\wx_pch.h -o wx_pch.h.gch\Debug_wx_pch_h_gch
g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -Winvalid-pch -include wx_pch.h -DWX_PRECOMP -Wall -g -IC:\wxWidgets-3.1.2\include -IC:\wxWidgets-3.1.2\lib\gcc_dll\mswu -c C:\Users\MC\Desktop\wxw\sac\GUIFrame.cpp -o obj\Debug\GUIFrame.o
windres.exe -IC:\wxWidgets-3.1.2\include -IC:\wxWidgets-3.1.2\lib\gcc_dll\mswu -J rc -O coff -i C:\Users\MC\Desktop\wxw\sac\resource.rc -o obj\Debug\resource.res
g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -Winvalid-pch -include wx_pch.h -DWX_PRECOMP -Wall -g -IC:\wxWidgets-3.1.2\include -IC:\wxWidgets-3.1.2\lib\gcc_dll\mswu -c C:\Users\MC\Desktop\wxw\sac\sacApp.cpp -o obj\Debug\sacApp.o
g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -Winvalid-pch -include wx_pch.h -DWX_PRECOMP -Wall -g -IC:\wxWidgets-3.1.2\include -IC:\wxWidgets-3.1.2\lib\gcc_dll\mswu -c C:\Users\MC\Desktop\wxw\sac\sacMain.cpp -o obj\Debug\sacMain.o
g++.exe -LC:\wxWidgets-3.1.2\lib\gcc_dll -o bin\Debug\sac.exe obj\Debug\GUIFrame.o obj\Debug\sacApp.o obj\Debug\sacMain.o obj\Debug\resource.res -mthreads -lwxmsw31u -mwindows
Process terminated with status 1 (0 minute(s), 11 second(s))
Process terminated with status 1 (0 minute(s), 11 second(s))
Process terminated with status 1 (0 minute(s), 12 second(s))
0 error(s), 0 warning(s) (0 minute(s), 12 second(s))
any help ?
This post assumes you have compiled wxWidgets 3.1.3 and are successful in compiling the executable samples via make and makefile.gcc that is included and are using gcc.
It also assumes you have already applied your environment vars in windows, applied your compiler flags wx-config --cxxflags and linker flag wx-config --libs.
It seems everyone else has dugout the makefile library order and has fixed it inside of codeblocks. I wanted to build small all in one apps so I decided on a MONOLITHIC with SHARED=0 UNICODE build.
It seems the easiest fix is thus.
CodeBlocks arranges the linker library order in a different order than the makefile does and jams up the linker, in my case varying from "theme" something or other to scrollbar issues.
So the quickest work around I've found is to delete all the entries in the codeblocks build options lists and enter only into the "Other Linker Options" for Debug and Release and this does work.
So from the console listing the makefile shows copy those linker settings in the order that makefile settings list. So until someone makes a header fixup entry for something higher than 2.8.8 there is this cumbersome workaround.
In my case the working order is as follows:
-mwindows
-lwxmsw31ud
-lwxmsw31ud_gl
-lwxscintillad
-lwxtiffd
-lwxjpegd
-lwxpngd
-lwxzlibd
-lwxregexud
-lwxexpatd
-lkernel32
-luser32
-lgdi32
-lcomdlg32
-lwinspool
-lwinmm
-lshell32
-lshlwapi
-lcomctl32
-lole32
-loleaut32
-luuid
-lrpcrt4
-ladvapi32
-lversion
-lwsock32
-lwininet
-loleacc
-luxtheme
In Release it is the same less the "d" which designates the debug file i.e.:
-lwxmsw31u_gl instead of -lwxmsw31ud_gl,
-lwxtiff in place of -lwxtiffd etc...

Compiling Simple static OpenGL 4.0 program using MinGW, freeglut and glew

The problem is in the title, I'll try to list what I've already tried and so on below.
First off, in my understanding, in order to use OpenGL 4.0 on windows you must extend and or bypass the default windows library as it only ships OpenGL 1.1.
So we have MinGW installed at C:/MinGW/. Next I setup FreeGLUT by downloading the tarball from the project site. Extract and compile by running the makefiles according to the instructions with a minor addition of --prefix to the ./configure command.
./configure --prefix=/c/Users/Owner/root/
make all
make install
Now I have freeglut in /c/Users/Owner/root/lib/, /c/Users/Owner/root/include/ and so on. Next up is GLEW, my problem child as far as I can tell.
Download the source archive from the project site (direct 1.7.0.zip link). Compiling is a tad more complicated, my current recipe is derived from the stack overflow question " Building glew on windows with mingw ". An abbreviated form is listed below:
mkdir lib/
mkdir bin/
gcc -DGLEW_NO_GLU -O2 -Wall -W -Iinclude -DGLEW_BUILD -o src/glew.o -c src/glew.c
gcc -shared -Wl,-soname,libglew32.dll -Wl,--out-implib,lib/libglew32.dll.a -o lib/glew32.dll src/glew.o -L/mingw/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32
ar cr lib/libglew32.a src/glew.o
gcc -DGLEW_NO_GLU -DGLEW_MX -O2 -Wall -W -Iinclude -DGLEW_BUILD -o src/glew.mx.o -c src/glew.c
gcc -shared -Wl,-soname,libglew32mx.dll -Wl,--out-implib,lib/libglew32mx.dll.a -o lib/glew32mx.dll src/glew.mx.o -L/mingw/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32
ar cr lib/libglew32mx.a src/glew.mx.o
and should be run from the "root" of /path/to/glew-1.7.0/.
Now with setup of libraries "done" (assuming no mistakes... ) compiling my simple program is done with this line.
${G++} -DFREEGLUT_STATIC -DGLEW_STATIC -m32 main.cpp -o main.exe -lfreeglut_static -lopengl32 -lwinmm -lgdi32 -lglew32 -I ${ROOTPATH}/include -L ${ROOTPATH}/lib --static
Now to decompose this a bit and walk through why I have various "extra" arguments and to show you what errors and problems I've already run into and solved.
-DFREEGLUT_STATIC and -lfreeglut_static are used instead of the normal -lfreeglut as we want a static build here. Failure to do this gives linker errors relating to freeglut.
-DGLEW_STATIC is added for the same reason.
-lwinmm is added to fix the linker error: freeglut_init.c:(.text+0x5d9): undefined reference to '_timeBeginPeriod#4'.
-lgdi32 is added to fix the linker error: c:/Users/Owner/root//lib\libfreeglut_static.a(freeglut_init.o):freeglut_init.c:(.text+0x58c): undefined reference to '_GetDeviceCaps#8'
Now I'm stumped with the following linker error:
c:/Users/Owner/root//lib\libglew32.a(glew.o):glew.c:(.text+0x83e8): undefined reference to `_glGetString#4'
c:/Users/Owner/root//lib\libglew32.a(glew.o):glew.c:(.text+0xa1b2): undefined reference to `_glGetString#4'
c:/Users/Owner/root//lib\libglew32.a(glew.o):glew.c:(.text+0xa290): undefined reference to `_glGetString#4'
The minimal test case that produces this error (main.cpp) is.
#include <GL/glew.h>
#include <GL/freeglut.h>
int main(int argc, char **argv) {
glEnableVertexAttribArray(0);
}
Ideas?
Try adding -lopengl32 last on the line to compile your program and see if it helps.
Argument order is significant with gcc linker options.
Try this:
${G++} -DFREEGLUT_STATIC -DGLEW_STATIC -m32 main.cpp -o main.exe -I ${ROOTPATH}/include -L ${ROOTPATH}/lib -lopengl32 -lwinmm -lgdi32 -lglew32 -static -lfreeglut_static
Also, I don't think there's a double-dash --static option, just -static.
And on win32 you're going to need a successful glewInit() before your glEnableVertexAttribArray() function pointer will be valid. After checking your core version and/or extension, of course :)

Mingw32 cross compiled console application doesn't do anything on Windows XP

I've compiled a small app in Linux (Ubuntu 11.04) with Mingw32 and it runs ok in Wine, but does nothing on Wuindows (although it runs).
Configure:
./configure --host=i586-mingw32msvc --target=i586-mingw32msvc --build=i686-linux
(I've tried without --target and without --build with the same results.)
Compile:
i586-mingw32msvc-g++ -DHAVE_CONFIG_H -I. -I.. -DLOG_DOMAIN=\"tpv\" -I.. -DWINVER=0x0400 -D_WINDOWS_ -Wall -g -Wl,--subsystem,console -mconsole -mms-bitfields -g -O2 -MT tpv-excepciones.o -MD -MP -MF .deps/tpv-excepciones.Tpo -c -o tpv-excepciones.o
Link:
/bin/bash ../libtool --tag=CXX --mode=link i586-mingw32msvc-g++ -Wall -g -Wl,--subsystem,console -mconsole -mms-bitfields -g -O2 -lstdc++ -lgcc -lodbc32 -lwsock32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lctl3d32 -lodbc32 -ladvapi32 -lodbc32 -lwsock32 -lopengl32 -lglu32 -lole32 -loleaut32 -luuid -lmingw32 -Wl,-subsystem,console -o tpv.exe tpv-excepciones.o tpv-conf.o tpv-main.o
It generates an .exe file which is not a linux binary.
It runs OK in wine, but does nothing in Windows XP.
Reading the web I've added some flags in configure time:
-Wl,--subsystem,console -mconsole -mms-bitfields
This is the program:
#include <windows.h>
#include "main.hh"
int main (int argc, char ** argv)
{
MessageBox (0, "Joder!", "Ermmm...", MB_OK);
//utils::conf c ("configuracion.3D");
//std::cout << "Valor de 'no': '" << c["TEXTO_ERROR"] << "'" << std::endl;
//std::cout << "..." << std::endl;
return 0;
}
I've tried everything I've found on the web to no avail.
Am I missing something?
Be sure to mark the application (in the PE32 executable header, I guess) as a "GUI" application, and not console. That is, use -mwindows with mingw (and not -mconsole). Your test source compiles fine (then it works) with this simple command (on Ubuntu 15.10 at least with deb package gcc-mingw-w64-i686 installed): i686-w64-mingw32-gcc -o test.exe test.c -mwindows.
I am far from being a Windows expert (not even a user too much ...), but as far as I know, Windows has a strict view that an application is console or GUI based, you can use the -mwindows switch to set this as "GUI application". I think, using a simple dialog box you've tried needs the application to be GUI based, and that could be the problem, that you haven't done that. A simple way to check your .exe:
lgb#antares:~$ file test.exe
test.exe: PE32 executable (GUI) Intel 80386, for MS Windows
Please note however, that a GUI application does not have console, so then you can't just printf() or other stdio functions to write to the console, because ... you haven't got a console :)

Compiling a Qt program in Windows XP with MinGW's g++

I have a stub Qt application and I keep getting compiler errors
#include <QApplication>
int main(int argc, char *argv[])
{
return 0;
}
I used qmake -project and qmake commands and as far as I can tell
they did their job correctly. When I subsequently call make at the command
line I get the following error:
g++ -c -O2 -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT
-DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I
'../../../../qt/include/QtCore' -I'../../../../qt/include/QtCore' -I'../../../..
/qt/include/QtGui' -I'../../../../qt/include/QtGui' -I'../../../../qt/include' -
I'.' -I'c:/qt/include/ActiveQt' -I'release' -I'.' -I'../../../../qt/mkspecs/defa
ult' -o release/Main.o Main.cpp
cc1plus.exe: Invalid option 'threads'
make[1]: *** [release/Main.o] Error 1
make: *** [release] Error 2
My searches on Google tell me that threading is important to keep but not how to
fix this error. Any help will be appreciated.
EDIT (copied from an answer the OP left):
I now get:
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-rel oc
-Wl,-s -pthread -Wl -Wl,-subsystem,windows -o release/raytrace.exe
object_scr ipt.raytrace.Release -L'c:/qt/lib' -lmingw32 -lqtmain -lQtGui -lgdi32
-lcomdlg3 2 -loleaut32 -limm32 -lwinmm -lwinspool -lmsimg32 -lQtCore -lkernel32
-luser32 - lshell32 -luuid -lole32 -ladvapi32 -lws2_32
g++: unrecognized option `-pthread'
/cygnus/cygwin-b20/H-i586-cygwin32/i586-cygwin32/bin/ld: cannot open -lmsimg32:
No such file or directory collect2:
ld returned 1 exit status make[1]: ***
[release/raytrace.exe] Error 1 make: *** [release] Error 2
++milot
I only use MinGW to compile Qt on Windows and that's the easiest way to make sure you have everything you need.
Here is the link for the Open Source Qt version:
http://trolltech.com/downloads/opensource/appdev/windows-cpp
Use the "Or download Qt with the MinGW compiler included: Size: 149,3 Mb" link.
The other way to use MinGW is to compile Qt with MinGW and then compile your application, but it depends on if you're compiling in MSYS or just using MinGW.
Well I had similar problem before when I was installing MingW downloaded from the web, but in the other hand while installing Qt it will ask you to download the version of MingW which is compatible with Qt. So have you tried installing it when the Qt installer asked you?
Qt 4.5 has Qt Creator 1.1 which is easy to develop applications.
Designing and coding is combined in Qt Creator and mucy easier to use.
you can experience it like using VB IDE(or rather like eclipse,netbeans,etc.)
when run the app. the project is compiled in either in debug or release mode.
Based on the later response from the questioner, not the original question.
From the MSYS prompt run "ls /mingw/lib/libmsimg32.a" and see if you have that file. My installation does (MinGW GCC 3.4.5). If you have that file you may need to add -L/mingw/lib. If you don't have the file you may have missed installing the windows api part of MinGW.
Either way remove -pthread. You're using the Win32 api.
If this doesn't work you need to specify which version of MinGW you're using and, if you're using MSYS, which version of MSYS.