Issue with compiling SFML project in CodeBlocks - c++

Made a simple sprite based 2d game in c++ using SFML. It compiles and runs just fine on linux but I want to be able to compile it on windows
I've downloaded the (supposed) right version of sfml for code::blocks this one from https://www.sfml-dev.org/download/sfml/2.5.1/ and configured the GNU GCC compiler search paths accordingly:
compiler search paths
linker search paths
c++11 standard enabled
After running the code I got 152 "undefined reference to ..." errors
Then after adding the libraries to the linker settings
linker settings
I got left with those 12 errors:
||=== Build file: "no target" in "no project" (compiler: unknown) ===|
C:\sfmltest\main.o:main.cpp|| undefined reference to _imp___ZN2sf5Music12openFromFileERKSs'| C:\sfmltest\main.o:main.cpp|| undefined reference to _imp___ZN2sf5Music12openFromFileERKSs'|
C:\sfmltest\main.o:main.cpp|| undefined reference to _imp___ZN2sf5Music12openFromFileERKSs'| C:\sfmltest\main.o:main.cpp|| undefined reference to _imp___ZN2sf5Music12openFromFileERKSs'|
C:\sfmltest\main.o:main.cpp|| undefined reference to _imp___ZN2sf4Font12loadFromFileERKSs'| C:\sfmltest\main.o:main.cpp|| undefined reference to _imp___ZN2sf7Texture12loadFromFileERKSsRKNS_4RectIiEE'|
C:\sfmltest\main.o:main.cpp|| undefined reference to _imp___ZN2sf7Texture12loadFromFileERKSsRKNS_4RectIiEE'| C:\sfmltest\main.o:main.cpp|| undefined reference to _imp___ZN2sf7Texture12loadFromFileERKSsRKNS_4RectIiEE'|
C:\sfmltest\main.o:main.cpp|| undefined reference to _imp___ZN2sf7Texture12loadFromFileERKSsRKNS_4RectIiEE'| C:\sfmltest\main.o:main.cpp|| undefined reference to _imp___ZN2sf7Texture12loadFromFileERKSsRKNS_4RectIiEE'|
C:\sfmltest\main.o:main.cpp|| more undefined references to `_imp___ZN2sf7Texture12loadFromFileERKSsRKNS_4RectIiEE' follow|
||error: ld returned 1 exit status|
||=== Build failed: 12 error(s), 0 warning(s) (0 minute(s), 2 second(s)) ===|
what am I missing?

You didn't define SFML_STATIC which is why the linker is looking for _imp___ (i.e. import) symbols.
Also your listed libraries is wrong. You should only list one set of libraries.
For example Static and Debug = sfml-*-s-d
Or Static and Release = sfml-*-s
And when you're statically linking, you also need to link SFML's dependencies.
If you follow the official tutorial on how to setup SFML with Code::Blocks step by step and don't just looking at the images, things should work just fine.

Related

Error: undefined reference to '...' after trying to build app in fresh system installation

I am developing c++ application in Win7 OS using GCC compiler and Code::Blocks as IDE. I have everything set up and everything works. Now i need to move whole development environment to virtual machine so i have installed system, IDE compiler, copied whole project. I double checked all libraries and options and they are same. When i try to build application i get this errors (50) from build log(relevant parts):
-------------- Build: Debug in MagicReportsFull (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Wall -std=c++11 -fexceptions -std=c++11 -g -IC:\Projects\MagicReportsFull\include -IC:\Projects\MagicReportsFull\ -I"C:\Program Files (x86)\CodeBlocks\MinGW" -IC:\Projects\MagicReportsFull -I"C:\Program Files (x86)\CodeBlocks\MinGW" -IC:\Projects\MagicReportsFull\include -c C:\Projects\MagicReportsFull\main.cpp -o obj\Debug\main.o
windres.exe -J rc -O coff -i C:\Projects\MAGICR~1\resource.rc -o obj\Debug\resource.res
windres.exe -J rc -O coff -i C:\Projects\MAGICR~1\version.rc -o obj\Debug\version.res
mingw32-g++.exe -LC:\Projects\MagicReportsFull\ -o bin\Debug\MagicReportsFull.exe obj\Debug\main.o obj\Debug\resource.res obj\Debug\version.res -lcomdlg32 -lgdi32 -luser32 -lshlwapi ..\..\CustomLibraries\lpng1636-build\libpng16.a ..\..\CustomLibraries\zlib-1.2.11-build\libzlibstatic.a ..\..\CustomLibraries\libharu-RELEASE_2_3_0-build\src\libhpdfs.a -lcomctl32 -mwindows
.
.
.
obj\Debug\main.o: In function `Z19CUSTOM_RegularTableP13_HPDF_Doc_RecP14_HPDF_Dict_RecffPfiS3_ic':
C:/Projects/MagicReportsFull/pdf.h:99: undefined reference to `HPDF_Page_Rectangle'
C:/Projects/MagicReportsFull/pdf.h:100: undefined reference to `HPDF_Page_Stroke'
C:/Projects/MagicReportsFull/pdf.h:102: undefined reference to `HPDF_Page_Rectangle'
C:/Projects/MagicReportsFull/pdf.h:103: undefined reference to `HPDF_Page_Stroke'
C:/Projects/MagicReportsFull/pdf.h:114: undefined reference to `HPDF_Page_MoveTo'
C:/Projects/MagicReportsFull/pdf.h:115: undefined reference to `HPDF_Page_LineTo'
C:/Projects/MagicReportsFull/pdf.h:116: undefined reference to `HPDF_Page_Stroke'
C:/Projects/MagicReportsFull/pdf.h:125: undefined reference to `HPDF_Page_MoveTo'
C:/Projects/MagicReportsFull/pdf.h:126: undefined reference to `HPDF_Page_LineTo'
C:/Projects/MagicReportsFull/pdf.h:127: undefined reference to `HPDF_Page_Stroke'
obj\Debug\main.o: In function `Z27CUSTOM_RegularTable_AddText20_CUSTOM_TableHandleriiPKhjccP14_HPDF_Dict_Recj':
C:/Projects/MagicReportsFull/pdf.h:198: undefined reference to `HPDF_Font_GetCapHeight'
C:/Projects/MagicReportsFull/pdf.h:232: undefined reference to `HPDF_Font_MeasureText'
C:/Projects/MagicReportsFull/pdf.h:294: undefined reference to `HPDF_Page_SetFontAndSize'
C:/Projects/MagicReportsFull/pdf.h:300: undefined reference to `HPDF_Font_MeasureText'
C:/Projects/MagicReportsFull/pdf.h:315: undefined reference to `HPDF_Page_BeginText'
C:/Projects/MagicReportsFull/pdf.h:316: undefined reference to `HPDF_Page_TextRect'
C:/Projects/MagicReportsFull/pdf.h:317: undefined reference to `HPDF_Page_EndText'
obj\Debug\main.o: In function `Z13pdf_generatorcPci':
C:/Projects/MagicReportsFull/pdf.h:347: undefined reference to `HPDF_New'
C:/Projects/MagicReportsFull/pdf.h:353: undefined reference to `HPDF_SetCompressionMode'
C:/Projects/MagicReportsFull/pdf.h:355: undefined reference to `HPDF_GetFont'
C:/Projects/MagicReportsFull/pdf.h:356: undefined reference to `HPDF_GetFont'
C:/Projects/MagicReportsFull/pdf.h:357: undefined reference to `HPDF_GetFont'
C:/Projects/MagicReportsFull/pdf.h:358: undefined reference to `HPDF_GetFont'
C:/Projects/MagicReportsFull/pdf.h:362: undefined reference to `HPDF_LoadPngImageFromFile'
C:/Projects/MagicReportsFull/pdf.h:442: undefined reference to `HPDF_AddPage'
C:/Projects/MagicReportsFull/pdf.h:444: undefined reference to `HPDF_Page_SetSize'
C:/Projects/MagicReportsFull/pdf.h:446: undefined reference to `HPDF_Page_SetLineWidth'
C:/Projects/MagicReportsFull/pdf.h:447: undefined reference to `HPDF_Page_SetLineWidth'
C:/Projects/MagicReportsFull/pdf.h:460: undefined reference to `HPDF_Page_DrawImage'
C:/Projects/MagicReportsFull/pdf.h:463: undefined reference to `HPDF_Page_BeginText'
C:/Projects/MagicReportsFull/pdf.h:464: undefined reference to `HPDF_Page_SetRGBFill'
C:/Projects/MagicReportsFull/pdf.h:465: undefined reference to `HPDF_Page_SetFontAndSize'
C:/Projects/MagicReportsFull/pdf.h:466: undefined reference to `HPDF_Page_TextRect'
C:/Projects/MagicReportsFull/pdf.h:467: undefined reference to `HPDF_Page_EndText'
C:/Projects/MagicReportsFull/pdf.h:685: undefined reference to `HPDF_AddPage'
C:/Projects/MagicReportsFull/pdf.h:687: undefined reference to `HPDF_Page_SetSize'
C:/Projects/MagicReportsFull/pdf.h:689: undefined reference to `HPDF_Page_SetLineWidth'
C:/Projects/MagicReportsFull/pdf.h:690: undefined reference to `HPDF_Page_SetLineWidth'
C:/Projects/MagicReportsFull/pdf.h:699: undefined reference to `HPDF_Page_DrawImage'
C:/Projects/MagicReportsFull/pdf.h:702: undefined reference to `HPDF_Page_BeginText'
C:/Projects/MagicReportsFull/pdf.h:703: undefined reference to `HPDF_Page_SetRGBFill'
C:/Projects/MagicReportsFull/pdf.h:704: undefined reference to `HPDF_Page_SetFontAndSize'
C:/Projects/MagicReportsFull/pdf.h:705: undefined reference to `HPDF_Page_TextRect'
C:/Projects/MagicReportsFull/pdf.h:706: undefined reference to `HPDF_Page_EndText'
C:/Projects/MagicReportsFull/pdf.h:829: undefined reference to `HPDF_AddPage'
C:/Projects/MagicReportsFull/pdf.h:831: undefined reference to `HPDF_Page_SetSize'
C:/Projects/MagicReportsFull/pdf.h:833: undefined reference to `HPDF_Page_SetLineWidth'
C:/Projects/MagicReportsFull/pdf.h:834: undefined reference to `HPDF_Page_SetLineWidth'
C:/Projects/MagicReportsFull/pdf.h:843: undefined reference to `HPDF_Page_DrawImage'
C:/Projects/MagicReportsFull/pdf.h:846: undefined reference to `HPDF_Page_BeginText'
Process terminated with status 1 (0 minute(s), 5 second(s))
50 error(s), 37 warning(s) (0 minute(s), 5 second(s))
As you can see, I am using LibHaru library which works flawlesly in guest system. Also i believe problem is not in library itself but in linker.
Project build options -> Linker settings -> Link libraries:
libcomdlg32.a
libgdi32.a
libuser32.a
libshlwapi.a
..\..\CustomLibraries\lpng1636-build\libpng16.a
..\..\CustomLibraries\zlib-1.2.11-build\libzlibstatic.a
..\..\CustomLibraries\libharu-RELEASE_2_3_0-build\src\libhpdfs.a
libcomctl32.a
I tried to do the same thing in Win7 virtual machine with same results. I am using same files as in guest system. Any ideas what went wrong?
I posted this question because i was not sure about linker settings being ok but since nobody said that its wrong i searched for other problems. So it turns out that i have been using wrong Program Files in Global compiler settings -> Toolchain executables. Also library order was wrong, LibHaru needed to be first and then other dependent libraries. Uninstalled GCC and IDE then installed correct version of GCC + IDE. Now it compiles without problem.
I suspect that reinstalling the compiler might have changed the version of MinGW, and maybe the library isn't compatible between these 2 versions.
I've had similar weird behaviour with MinGW before, and recompiling the dependencies myself with the same compiler fixed the issue (it's a tedious solution though).
Are the compiler and system exactly the same ? (same architecture, version, etc)
Check if you havent copied some codeblocks environment specific files from the previous system, maybe codeblocks is trying to compile with options that doesn't apply to your new environment.
Does the libhpdfs headers have system dependent defines ?
Did you compile libhpdfs.a yourself ?
Did you try recompiling it yourself on the virtual machine ?

"Undefined reference" errors when including <iostream>

I have started a new console application (C++) in Code::Blocks 17.12 with Cygwin compiler and g++ 7.3.0, and I have only "main.cpp" which have a very small code:
#include<iostream>
using namespace std;
int main(){
cout<<"test";
return 0;
}
I clicked build and got 16 errors, Here's the build log:
-------------- Build: Debug in 1 (compiler: Cygwin g++)---------------
g++.exe -Wall -fexceptions -g -std=c++14 -IC:\cygwin\usr\include -c C:\Users\Windows7\Desktop\BASIL\1\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -LC:\cygwin\lib -o bin\Debug\1.exe obj\Debug\main.o
obj\Debug\main.o: In function `_static_initialization_and_destruction_0':
/usr/lib/gcc/i686-pc-cygwin/7.3.0/include/c++/iostream:74: undefined reference to `__dso_handle'
/usr/lib/gcc/i686-pc-cygwin/7.3.0/include/c++/iostream:74: undefined reference to `__cxa_atexit'
C:\cygwin\lib/libpthread.a(t-d001702.o):fake:(.text+0x2): undefined reference to `_imp__pthread_mutex_destroy'
C:\cygwin\lib/libpthread.a(t-d001704.o):fake:(.text+0x2): undefined reference to `_imp__pthread_mutex_init'
C:\cygwin\lib/libpthread.a(t-d001709.o):fake:(.text+0x2): undefined reference to `_imp__pthread_mutex_unlock'
C:\cygwin\lib/libpthread.a(t-d001720.o):fake:(.text+0x2): undefined reference to `_imp__pthread_once'
C:\cygwin\lib/libpthread.a(t-d001705.o):fake:(.text+0x2): undefined reference to `_imp__pthread_mutex_lock'
C:\cygwin\lib/libpthread.a(t-d001699.o):fake:(.text+0x2): undefined reference to `_imp__pthread_key_create'
C:\cygwin\lib/libpthread.a(t-d001697.o):fake:(.text+0x2): undefined reference to `_imp__pthread_getspecific'
C:\cygwin\lib/libpthread.a(t-d001741.o):fake:(.text+0x2): undefined reference to `_imp__pthread_setspecific'
C:\cygwin\lib/libpthread.a(t-d001679.o):fake:(.text+0x2): undefined reference to `_imp__pthread_cond_wait'
C:\cygwin\lib/libpthread.a(t-d001674.o):fake:(.text+0x2): undefined reference to `_imp__pthread_cond_broadcast'
C:\cygwin\lib/libpthread.a(t-d001700.o):fake:(.text+0x2): undefined reference to `_imp__pthread_key_delete'
C:\cygwin\lib/libpthread.a(t-d001675.o):fake:(.text+0x2): undefined reference to `_imp__pthread_cond_destroy'
C:\cygwin\lib/libpthread.a(t-d001677.o):fake:(.text+0x2): undefined reference to `_imp__pthread_cond_signal'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 3 second(s))
16 error(s), 0 warning(s) (0 minute(s), 3 second(s))
I also edited the compiler, the linker and the resource compiler in search directories tab according to the documentation but that didn't work.
please help me in this!
Thanks,
Finally fixed it! Just giving the answer to people still searching,
just install Cygwin and go to settings -> compiler in code::blocks and pick Cygwin GCC instead of GNU GCC compiler, go to the Toolchain excutables and change the "Compiler's Installation Directory" to your Cygwin directory and change the "Program files" to your cygwin programs (if they're not already modified), the compiler window should look like the screenshot attached.

undefined reference with irrklang code blocks

I'm losing hope to finish my work. I did a game with irrlicht on Code Blocks. I linked irrlicht it works but impossible to link irrKlang...
It shows me the same message each time.
x86_64-w64-mingw32-g++.exe -Llib\irrlicht-1.8.3\lib\Win32-gcc -Llib\irrKlang-1.5.0\lib\Win32-gcc -Llib\irrlicht-1.8.3\lib\Win32-gcc -Llib\irrKlang-1.5.0\lib\Win32-gcc -Llib\irrKlang-1.5.0\bin\win32-gcc -o BomberPark.exe .objs\main.o .objs\srcs\AppSetting.o .objs\srcs\Bombs.o .objs\srcs\Camera.o
.objs\srcs\Sound.o:Sound.cpp:(.text+0x24): undefined reference to irrklang::createIrrKlangDevice(irrklang::E_SOUND_OUTPUT_DRIVER, int, char const*, char const*)'
collect2.exe: error: ld returned 1 exit status
I did these things: I added the libirrklang.a in link librairies and add the directory of the includes in compiler + added the lib directory in linker so I wanted to know what else can I do to resolve my problem please?
The screenshots of my configuration for the linker:
conf1
conf3

__imp link errors using g++ running under mingw

I have a simple socket program that I'm trying to compile using g++ running in mingw (both the latest versions) on a Win8 system. I'm getting the common linker errors
undefined reference to `__imp_socket'
undefined reference to `__imp_gethostbyname'
I've tried adding -lws2_32 with no luck; i.e. it still can't find the references. Can someone suggest something else I might be missing?
Here's the full output:
G:\source\kak>g++ -o ./test_client -lws2_32 test_client.C
C:\Users\kenkahn\AppData\Local\Temp\ccDZTr9b.o:test_client.C:(.text+0x4f): undefined reference to `__imp_inet_addr'
C:\Users\kenkahn\AppData\Local\Temp\ccDZTr9b.o:test_client.C:(.text+0x6b): undefined reference to `__imp_socket'
C:\Users\kenkahn\AppData\Local\Temp\ccDZTr9b.o:test_client.C:(.text+0x8b): undefined reference to `__imp_connect'
d:/program files/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\kenkahn\AppData\Local\Temp\ccDZTr9b.o: bad reloc address 0xc in section `.xdata'
collect2.exe: error: ld returned 1 exit status
Try putting the -lws2_32 after the test_client.C parameter. The linker of gcc (ld) is touchy about the order of linkable things, this is probably why it doesn't find your imported functions at link time.

Eclipse integrate with qt

i download qt and eclipse with c++ cdt , i see that qt come with qt ide (qt creator) , to develop qt appliation and that fine , but i want to do this wit eclipse , i mean use c++ code with qt inside eclipse . is there any ? because i am trying to use qt to design my user interface only and using other code from other libraries to do other things .
i try to include header files (usr/include/qt4) , but i still have a problem when i compile the program such us ( can't find qgui.h ) any help the integrate qt with eclipse like netbeans .
edit :
here is my output
13:48:48 **** Incremental Build of configuration Debug for project test ****
Info: Internal Builder is used for build
g++ -o test src/test.o -lQtCore
src/test.o: In function `main':
/media/sda2/workspaceeclipse/test/Debug/../src/test.cpp:6: undefined reference to `QApplication::QApplication(int&, char**, int)'
/media/sda2/workspaceeclipse/test/Debug/../src/test.cpp:8: undefined reference to `QPushButton::QPushButton(QString const&, QWidget*)'
/media/sda2/workspaceeclipse/test/Debug/../src/test.cpp:12: undefined reference to `QApplication::exec()'
/media/sda2/workspaceeclipse/test/Debug/../src/test.cpp:12: undefined reference to `QPushButton::~QPushButton()'
/media/sda2/workspaceeclipse/test/Debug/../src/test.cpp:12: undefined reference to `QApplication::~QApplication()'
/media/sda2/workspaceeclipse/test/Debug/../src/test.cpp:8: undefined reference to `QPushButton::~QPushButton()'
/media/sda2/workspaceeclipse/test/Debug/../src/test.cpp:12: undefined reference to `QPushButton::~QPushButton()'
/media/sda2/workspaceeclipse/test/Debug/../src/test.cpp:12: undefined reference to `QApplication::~QApplication()'
src/test.o: In function `QWidget::resize(int, int)':
/usr/include/qt4/QtGui/qwidget.h:996: undefined reference to `QWidget::resize(QSize const&)'
collect2: error: ld returned 1 exit status
13:48:49 Build Finished (took 1s.609ms)
I had to adjust the following settings in "Project Properties => C/C++ General => Paths and Symbols":
On the "Includes" tab, for the GNU C++ language, add the following include paths:
/usr/include/qt4
/usr/include/qt4/QtCore
/usr/include/qt4/QtGui
On the "Symbols" tab, for the GNU C++ language, define the following symbols with a value of "1" (might be different for you, but at least the QT_CC_GNU, QT_CORE_LIB and QT_GUI_LIB are necessary):
QT_CC_GNU
QT_CORE_LIB
QT_GUI_LIB
QT_NO_DEBUG
QT_SHARED
QT_TESTLIB_LIB
QT_WEBKIT
With these settings, the source indexer works well. Other than that, Eclipse is simply calling "make" for the build.