News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Trouble compiling/linking

Started by Svalorzen, May 10, 2012, 12:55:10 PM

Previous topic - Next topic

Svalorzen

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:
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

Quoteg++ -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!

stahta01

#1
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.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

Svalorzen

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?

stahta01

#3
Quote from: Svalorzen 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?

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.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

Svalorzen

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.

stahta01

Quote from: Svalorzen 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.

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++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

Svalorzen

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.

stahta01

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.

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++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

Svalorzen

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.

stahta01

Please READ the Rules

http://forums.next.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++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

Svalorzen

Sure man.

Quote5. 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.

Svalorzen

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?


oBFusCATed

-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!]

Svalorzen

#13
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?

oBFusCATed

Quote from: Svalorzen on May 10, 2012, 07:53:32 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!]