Author Topic: Trouble compiling/linking  (Read 6666 times)

Offline Svalorzen

  • Multiple posting newcomer
  • *
  • Posts: 11
Trouble compiling/linking
« on: May 10, 2012, 12:55:10 pm »
Good morning everyone, I'm having some trouble getting the compilation for a particular project to work on Code::Blocks.

I recently discovered the FLTK library for GUI on Windows, and after setting it up I opened a test project to try and make it work. Unfortunately when I try to compile it I get 19 linker errors:
Code: [Select]
g++.exe -LC:\Users\Svalorzen\Documents\Projects\fltk-1.3.0\lib  -o bin\Debug\test.exe obj\Debug\main.o   -mwindows -lole32 -luuid -lcomctl32  C:\Users\Svalorzen\Documents\Projects\fltk-1.3.0\lib\libfltk.a
C:\Users\Svalorzen\Documents\Projects\fltk-1.3.0\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0x2bb): undefined reference to `OleUninitialize@0'
C:\Users\Svalorzen\Documents\Projects\fltk-1.3.0\lib\libfltk.a(Fl.o):Fl.cxx:(.text+0x738): undefined reference to `OleInitialize@4'
...

However if I compile the project from command prompt ( or even Msys ), with this script

Quote
g++ -I..\fltk-1.3.0\ -mwindows -DWIN32 -DUSE_OPENGL32 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -o 'main' main.cpp -mwindows ..\fltk-1.3.0\lib\libfltk.a -lole32 -luuid -lcomctl32

it compiles correctly. I've attached an image with the settings of my Code::Blocks, what exactly am I doing wrong?

Thanks in advance!

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6466
    • My Best Post
Re: Trouble compiling/linking
« Reply #1 on: May 10, 2012, 01:09:13 pm »
In linking the order matters.
You put the libraries in a different order.
The libfltk.a is at the end of the command that fails to work and close to the beginning of the one that works.

Tim S.
« Last Edit: May 10, 2012, 01:10:48 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Svalorzen

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Trouble compiling/linking
« Reply #2 on: May 10, 2012, 01:17:40 pm »
Thanks! Unfortunately, I did not write the line that does not work. That would be Code::Blocks. I just setup the include/linking variables.

How can I change the order of the libraries?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6466
    • My Best Post
Re: Trouble compiling/linking
« Reply #3 on: May 10, 2012, 01:33:36 pm »
Thanks! Unfortunately, I did not write the line that does not work. That would be Code::Blocks. I just setup the include/linking variables.

How can I change the order of the libraries?

You put the libraries in Code::Blocks; that picked the order.
Re-order the libraries in Code::Blocks.

The box called "Link Libraries" should have all the libraries in it.
Order them the correct way.

Select one of the library and the up/down arrows should appear.

Tim S.
« Last Edit: May 10, 2012, 01:36:06 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Svalorzen

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Trouble compiling/linking
« Reply #4 on: May 10, 2012, 01:40:02 pm »
Is it the only way? Mostly because I'm not sure what libraries are those, I just pasted a script.. also it does not sound incredibly efficient.

If it is I'll do it though.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6466
    • My Best Post
Re: Trouble compiling/linking
« Reply #5 on: May 10, 2012, 01:49:19 pm »
Is it the only way? Mostly because I'm not sure what libraries are those, I just pasted a script.. also it does not sound incredibly efficient.

If it is I'll do it though.

You can do whatever you want.

Bye, I will not likely be answering any of your future questions.

This site is NOT used to teach programing.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Svalorzen

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Trouble compiling/linking
« Reply #6 on: May 10, 2012, 01:54:30 pm »
What does that even have to do with programming?
I have a line script that works, and I'm trying to get Code::Blocks to reproduce it.

I'm trying to understand if there is a way to specify orders in the linker options vs linker libraries.
Why do you have to be so harsh? My program compiles so definitely it IS NOT a programming question.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6466
    • My Best Post
Re: Trouble compiling/linking
« Reply #7 on: May 10, 2012, 02:17:28 pm »
If you do NOT know what a library is then you do NOT know enough to program.
I will help you this time; but, you need to learn how to program.

Code: [Select]
g++ -I..\fltk-1.3.0\ -mwindows -DWIN32 -DUSE_OPENGL32 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -o 'main' main.cpp -mwindows ..\fltk-1.3.0\lib\libfltk.a -lole32 -luuid -lcomctl32

The clear libraries in your above command are
ole32
uuid
comctl32


The not so clear one is
libfltk.a


You need to really know the difference between compiler and linking to understand some basic things in programming.

If you DO NOT wish to use an IDE do NOT do so; do NOT complain that it is NOT efficient because you need to learn something.

NOTE: The efficient way to program may or may NOT be with an IDE; but, you do not seem to know the basic needed to judge which is more efficient.

Tim S.






C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Svalorzen

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Trouble compiling/linking
« Reply #8 on: May 10, 2012, 02:31:56 pm »
I'm sorry if you did wake up extremely angry this morning, you should seriously vent some other place.

I'm not complaining about anything, the only thing I was saying was inefficient would be searching manually for the ole32, uuid and comctl32 libraries within my filesystem and add them to the Linker Settings->Linker Libraries instead of using the Linker Options which should be the expected solution, since linking options are used in every project in existence.

There is nothing else to understand, as you said I probably have to change the library linking order but I cannot see ways to mix the order of Libraries/Options together, I only saw options to prepend ALL of the Options to the Libraries or append ALL of them to the Libraries.

Again, it's the only thing that I'm asking and if you don't feel like answering but only attack me I kindly ask you to not do that, I'll wait for some more helping person.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6466
    • My Best Post
Re: Trouble compiling/linking
« Reply #9 on: May 10, 2012, 02:46:57 pm »
Please READ the Rules

http://forums.codeblocks.org/index.php/topic,9996.0.html


There is something worse than ignorance, and that's knowing what ain't so. - Mark Twain

Tim S.


C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Svalorzen

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Trouble compiling/linking
« Reply #10 on: May 10, 2012, 02:50:32 pm »
Sure man.

Quote
5. Before posting, look where you post. There's the "Using CodeBlocks" board to help newbies set up their compilers and change their configuration.

Whoop de doop, that is what I am trying to do. Now please just stop.

Offline Svalorzen

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Trouble compiling/linking
« Reply #11 on: May 10, 2012, 07:09:12 pm »
I manage to fix the order by putting everything into the Linker/Compiler Options and by not using the Search Directories nor the Linker Libraries. I still don't think this is an ideal solution, but it works.

However one single linker error still remains. I've copied the EXACT same command that Code::Blocks shows on the command prompt and there it works fine. I really don't understand this.

Is the IDE not telling me all the things it is effectively doing?


Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11583
    • Travis build status
Re: Trouble compiling/linking
« Reply #12 on: May 10, 2012, 07:39:26 pm »
-l is equivalent to putting the library in the options
-L is equivalent to putting the path in to the linker search path
Are you sure you use the same compiler in c::b and outside c::b?

Don't post the build logs as images, because then searching for them in google is problematic.
Also don't attach images directly, but use an image hosting service and post links. This is because the space on the forum is limited.

See this:
http://www.allegro.cc/forums/thread/610175
http://stackoverflow.com/questions/9703266/itpp-link-undefined-reference-to-chkstk-ms-using-qtcreator
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Svalorzen

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Trouble compiling/linking
« Reply #13 on: May 10, 2012, 07:53:32 pm »
Thanks! It turns out, in fact, that they were not and I completely forgot of the MinGW installation within the Codeblocks directory. After I setup CodeBlocks to use the same one as the prompt one it works just fine. My bad again.

I didn't know I shouldn't attach images, I assumed the option was there to be used. I won't do it again! =)

And I attached the image just to show that the scripts were the same.

Since you responded I'll just ask again my first problem: is there actually a way to pick the order in which Linker Options and Libraries gets printed out?
« Last Edit: May 10, 2012, 07:57:57 pm by Svalorzen »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11583
    • Travis build status
Re: Trouble compiling/linking
« Reply #14 on: May 10, 2012, 08:03:02 pm »
Since you responded I'll just ask again my first problem: is there actually a way to pick the order in which Linker Options and Libraries gets printed out?
Top-to-bottom translates to left-to-right. If you ask for the library order in the linker command, of course.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]