Author Topic: Problem with linking libraries  (Read 21180 times)

rem

  • Guest
Problem with linking libraries
« on: June 08, 2005, 08:18:55 pm »
When i create new project with static wxWidgets library the code::blocks doesn't generate the exe file, the compilers gives me the message:

Project   : Project1
Compiler  : GNU GCC Compiler (called directly)
Directory : C:\Dev-Cpp\Projects\3\
--------------------------------------------------------------------------------
Switching to target: default
Compiling: myapp.cpp
Compiling: main.cpp
Linking executable: C:\Dev-Cpp\Projects\3\Project1.exe
C:\Program Files\CodeBlocks\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lwxmsw26 -lwxmsw26_gl -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregex -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 44 seconds)
 
I really don't know why, I added to the linker options all libraries

-lwxmsw26 -lwxmsw26_gl -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregex -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32

But still without effect, then I changed the libraries to the path, like below:

C:\Dev-Cpp\lib\libwxmsw26.a ... and all other

And still nothing, any sugestions, thank you very much for any.

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Problem with linking libraries
« Reply #1 on: June 08, 2005, 09:42:56 pm »
hmmmmmmmm what version of Code::Blocks are you using? (Did you grab it from CVS or just downloaded it from the web?

Second, did you install the wxWidgets (NOT included in Code::Blocks) ?

Anonymous

  • Guest
Problem with linking libraries
« Reply #2 on: June 09, 2005, 03:09:07 am »
"hmmmmmmmm what version of Code::Blocks are you using?"
1.0 final beta

"Did you grab it from CVS or just downloaded it from the web?"
I downloaded it from
http://www.codeblocks.org/modules.php?op=modload&name=Downloads&file=index

"Second, did you install the wxWidgets (NOT included in Code::Blocks) ?"
Yes, I did, I used Dev-cpp, but I wanted to change it to Code::Blocks

rem

  • Guest
Problem with linking libraries
« Reply #3 on: June 09, 2005, 03:09:57 am »
The last submit it was me. rem.  :lol:

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Problem with linking libraries
« Reply #4 on: June 09, 2005, 11:24:08 am »
Post the *full* compile log. Enable it in "Compiler->Compiler options->Other->Compiler logging".
The error says it can't find the libs. Have you added the correct directories???

Yiannis.
Be patient!
This bug will be fixed soon...

rem

  • Guest
Problem with linking libraries
« Reply #5 on: June 09, 2005, 11:58:22 am »
Finally I succeed to link the program. I've changed the Compiler -> Compiler Options -> Other -> Build method -> Work with Makefiles (GNU "make" is required). I've also changed the libraries from:

-lwxmsw26 -lwxmsw26_gl -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregex -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32

to
 wxmsw26 -lwxmsw26_gl -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregex -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32

It's because the code::blocks probably adds -l on the beggining and if you do that to the linked libraries will look like this

-l-lwxmsw26 -lwxmsw26_gl -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregex -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32

Thanks for the help.

rem

  • Guest
Problem with linking libraries
« Reply #6 on: June 09, 2005, 12:18:09 pm »
I'm really confused about the linking.

I add this libraries
 wxmsw26 -lwxmsw26_gl -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregex -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32

and I get this:

Project   : wxWidgets application
Compiler  : GNU GCC Compiler (using GNU "make")
Directory : C:\Dev-Cpp\Projects\5\
--------------------------------------------------------------------------------
mingw32-g++.exe  -LC:/Program\ Files/CodeBlocks/lib -LC:/Dev-Cpp/lib -o C:/Dev-Cpp/Projects/5/wxWidgets.exe .objs/main.o .objs/app.o      -l-lwxmsw26 -lwxmsw26_gl -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregex -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lwxmsw26 -lwxmsw26_gl -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregex -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -mwindows
C:\Program Files\CodeBlocks\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -l-lwxmsw26
collect2: ld returned 1 exit status
make.exe: *** [C:/Dev-Cpp/Projects/5/wxWidgets.exe] Error 1
Process terminated with status 1 (0 minutes, 0 seconds)
 
Why there is -l-lwxmsw26 if I add wxmsw26 in the linker libraries.

DreadNot

  • Guest
Problem with linking libraries
« Reply #7 on: June 09, 2005, 01:01:00 pm »
Put -l back on wxmsw26.  I looks like you don't have directory paths setup for the linker properly.  It should be "C:\Dev-Cpp\lib" and other such directories.  wxWidgets are generally in "...somewhere\wxWidgets-2.6.x\lib\gcc_dll" or some such place.

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Problem with linking libraries
« Reply #8 on: June 09, 2005, 01:46:02 pm »
If you add the libs in the "Link libraries" box, you don't have to use "-l".
If you put it in "Other linker options" you must put "-l".

Also, if possible, use the "direct-mode" instead of "make". there are some known bugs with "make" and I 'm working on them.

Yiannis.
Be patient!
This bug will be fixed soon...

rem

  • Guest
Problem with linking libraries
« Reply #9 on: June 09, 2005, 05:54:06 pm »
Project   : Project1
Compiler  : GNU GCC Compiler (called directly)
Directory : C:\Dev-Cpp\Projects\3\
--------------------------------------------------------------------------------
Switching to target: default
mingw32-g++.exe   -Wall -pg -g -fno-rtti -fno-exceptions -fno-pcc-struct-return -fstrict-aliasing -Wall -D__WXMSW__ -D__GNUWIN32__ -D__WIN95__  -Wall    -I"C:\Program Files\CodeBlocks\include" -IC:\Dev-Cpp\include -c myapp.cpp -o .objs\myapp.o
mingw32-g++.exe   -Wall -pg -g -fno-rtti -fno-exceptions -fno-pcc-struct-return -fstrict-aliasing -Wall -D__WXMSW__ -D__GNUWIN32__ -D__WIN95__  -Wall    -I"C:\Program Files\CodeBlocks\include" -IC:\Dev-Cpp\include -c main.cpp -o .objs\main.o
mingw32-g++.exe    -L"C:\Program Files\CodeBlocks\lib" -LC:\Dev-Cpp\lib -o C:\Dev-Cpp\Projects\3\Project1.exe .objs\myapp.o .objs\main.o    -pg -lgmon      -l"wxmsw26 wxmsw26_gl wxtiff wxjpeg wxpng wxzlib wxregex wxexpat kernel32 user32 gdi32 comdlg32 winspool winmm shell32 comctl32 ole32 oleaut32 uuid rpcrt4 advapi32 wsock32" -mwindows
C:\Program Files\CodeBlocks\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lwxmsw26 wxmsw26_gl wxtiff wxjpeg wxpng wxzlib wxregex wxexpat kernel32 user32 gdi32 comdlg32 winspool winmm shell32 comctl32 ole32 oleaut32 uuid rpcrt4 advapi32 wsock32
collect2: ld returned 1 exit status
Process terminated with status 1 (1 minutes, 15 seconds)
0 errors, 0 warnings
 

 
All libriaries linked in this project are in one directory
C:\Dev-cpp\lib

And it is added to the linker directories

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Problem with linking libraries
« Reply #10 on: June 09, 2005, 06:30:58 pm »
HUH? :shock:

-l"wxmsw26 wxmsw26_gl wxtiff wxjpeg wxpng wxzlib wxregex wxexpat kernel32 user32 gdi32 comdlg32 winspool winmm shell32 comctl32 ole32 oleaut32 uuid rpcrt4 advapi32 wsock32"

Dude, you put all the libraries in one BIG linker option!
You better drop all those, and add them ONE BY ONE.

Anonymous

  • Guest
Problem with linking libraries
« Reply #11 on: June 09, 2005, 07:45:27 pm »
Ok, finally I have compiled the project. All libraries should be added separatly  Problems are solved, but I had one more adventure with linking.

I started new project in the Code::Blocks and then added libraries, and the compile log looked like below:

Project   : wxWidgets application
Compiler  : GNU GCC Compiler (called directly)
Directory : C:\Dev-Cpp\Projects\4\
--------------------------------------------------------------------------------
Switching to target: default
mingw32-g++.exe   -pipe -mthreads -fno-pcc-struct-return -fno-rtti -fno-exceptions -D_X86_ -DWIN32 -D_WIN32 -DWINVER=0x0400 -D__WIN95__ -D__GNUWIN32__ -D__WIN32__ -DSTRICT -D__WXMSW__ -D__WINDOWS__  -Wall    -I"C:\Program Files\CodeBlocks\include" -IC:\Dev-Cpp\include -c main.cpp -o .objs\main.o
mingw32-g++.exe   -pipe -mthreads -fno-pcc-struct-return -fno-rtti -fno-exceptions -D_X86_ -DWIN32 -D_WIN32 -DWINVER=0x0400 -D__WIN95__ -D__GNUWIN32__ -D__WIN32__ -DSTRICT -D__WXMSW__ -D__WINDOWS__  -Wall    -I"C:\Program Files\CodeBlocks\include" -IC:\Dev-Cpp\include -c app.cpp -o .objs\app.o
mingw32-g++.exe    -L"C:\Program Files\CodeBlocks\lib" -LC:\Dev-Cpp\lib -o C:\Dev-Cpp\Projects\4\wxWidgets.exe .objs\main.o .objs\app.o        -lwxmsw -lwinspool -lwinmm -lshell32 -lcomctl32 -lctl3d32 -lodbc32 -ladvapi32 -lwsock32 -lopengl32 -lglu32 -lole32 -loleaut32 -luuid  -lwxmsw26 -lwxmsw26_gl -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregex -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32 -lopengl32 -mwindows
C:\Program Files\CodeBlocks\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lwxmsw
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 37 seconds)
0 errors, 0 warnings

Strange is that I didn't added all libraries from the log
-lwxmsw -lwinspool -lwinmm -lshell32 -lcomctl32 -lctl3d32 -lodbc32 -ladvapi32 -lwsock32 -lopengl32 -lglu32 -lole32 -loleaut32 -luuid  -lwxmsw26 -lwxmsw26_gl -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregex -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32 -lopengl32

A added only libraries below:
-lwxmsw26 -lwxmsw26_gl -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregex -lwxexpat -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32 -lopengl32

So I removed all libraries I added in the linker options, and the compile log looks like below:

Project   : wxWidgets application
Compiler  : GNU GCC Compiler (called directly)
Directory : C:\Dev-Cpp\Projects\4\
--------------------------------------------------------------------------------
Switching to target: default
mingw32-g++.exe   -pipe -mthreads -fno-pcc-struct-return -fno-rtti -fno-exceptions -D_X86_ -DWIN32 -D_WIN32 -DWINVER=0x0400 -D__WIN95__ -D__GNUWIN32__ -D__WIN32__ -DSTRICT -D__WXMSW__ -D__WINDOWS__  -Wall    -I"C:\Program Files\CodeBlocks\include" -IC:\Dev-Cpp\include -c main.cpp -o .objs\main.o
mingw32-g++.exe   -pipe -mthreads -fno-pcc-struct-return -fno-rtti -fno-exceptions -D_X86_ -DWIN32 -D_WIN32 -DWINVER=0x0400 -D__WIN95__ -D__GNUWIN32__ -D__WIN32__ -DSTRICT -D__WXMSW__ -D__WINDOWS__  -Wall    -I"C:\Program Files\CodeBlocks\include" -IC:\Dev-Cpp\include -c app.cpp -o .objs\app.o
mingw32-g++.exe    -L"C:\Program Files\CodeBlocks\lib" -LC:\Dev-Cpp\lib -o C:\Dev-Cpp\Projects\4\wxWidgets.exe .objs\main.o .objs\app.o        -lwxmsw -lwinspool -lwinmm -lshell32 -lcomctl32 -lctl3d32 -lodbc32 -ladvapi32 -lwsock32 -lopengl32 -lglu32 -lole32 -loleaut32 -luuid  -mwindows
C:\Program Files\CodeBlocks\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lwxmsw
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 34 seconds)
0 errors, 0 warnings

I was confused, why code::blocks adds libraries by it self, and I remind my self, that there I had problems with starting new static wxWidgets project, there was no file wxwindows_static.cbm file, and someone on the forum sad that these who have the problem should copy this file from the url:

http://cvs.sourceforge.net/viewcvs.py/*checkout*/codeblocks/codeblocks/src/templates/win32/wxwidgets_static.cbp?rev=1.1

and save it in the code::blocks directory, and I found that these libraries are in this file
      <Linker>
         <Add library="wxmsw"/>
         <Add library="winspool"/>
         <Add library="winmm"/>
         <Add library="shell32"/>
         <Add library="comctl32"/>
         <Add library="ctl3d32"/>
         <Add library="odbc32"/>
         <Add library="advapi32"/>
         <Add library="wsock32"/>
         <Add library="opengl32"/>
         <Add library="glu32"/>
         <Add library="ole32"/>
         <Add library="oleaut32"/>
         <Add library="uuid"/>
      </Linker>

So if anyone has the same problem, just removed these lines from the wxwindows_static.cbp file. Thank you for the help.

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Problem with linking libraries
« Reply #12 on: June 09, 2005, 09:03:46 pm »
Good. Now the problem is that you can't find "libwxmsw.a".

C:\Program Files\CodeBlocks\bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32\bin\ld.exe: cannot find -lwxmsw
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 34 seconds)
0 errors, 0 warnings

Now, there MUST be a libwxmsw.a file SOMEWHERE. You just have to add its folder to your linker directories in your project options. Don't give up, you're about to find it :)

Anonymous

  • Guest
Problem with linking libraries
« Reply #13 on: June 11, 2005, 01:58:26 pm »
libwxmsw.a was in the wxWindows_static.cbp template, I had problems with starting new project with wxWidgets static library, because there was no wxWindows_static.cbp file in the template directory. So I copied it from the url
http://cvs.sourceforge.net/viewcvs.py/*checkout*/codeblocks/codeblocks/src/templates/win32/wxwidgets_static.cbp?rev=1.1
and in this file wxmsw was in the linker options. So I removed it from this file, and the problem was solved. Thank all of you for your help