Page 1 of 1

Question regarding making libraries

Posted: Sat Mar 30, 2013 1:35 am
by Moonkis
I have a few questions as well as a few errors when trying to make a library, I'd like to appologise in advance if I come off as stupid, but I'm very new to g++ and CodeLite in general, I come from a very protective Microsoft Visual C++ where a lot of things happened automagically so try to have some understanding and don't judge me too hard.

So here is my specs:

OS - Windows 7
IDE - CodeLite 5.1


1) When making a g++ shared dynamic library I get an *.so file instead of an .dll file and a lib file to link against.
I'v come to terms that you link against an *.so file and then you can rename it and use it as a .dll file for the .exe

Have I grasped this correctly?

2) Is there an easy way to alternate between an static and shared build? Currently I'm running two projects.

3)Vildhjarta that is my library uses files from SFML to work, I link to SFML statically and it outputs a rather large .so file, which is understandable but also I don't need to link to SFML when linking to my library seeing as it includes all the necessary classes from the SFML library to run.
This is not a problem mostly a curiosity.

When doing my .dll file in Microsoft Visual C++ the library ( even when statically linking ) outputs a minimal version of the .dll file and still requires me to link towards SFML in addition to my own library when using it in a project.

How do I mimic that behavior in g++? If I can? Basically I need to use the SFML library when compiling my own library, but I don't want to link dynamically because that would mean I would require to have SFML present as .dll files? Or would it detect an statically linked SFML? It makes me confused.

Making a dynamic shared library is all good but trying to make a static version of it fails.
Here is the output:
C:\Windows\system32\cmd.exe /c "mingw32-make.exe -j 4 -e -f "Vildhjarta_wsp.mk""
"----------Building project:[ VildhjartaStatic - Debug ]----------"
mingw32-make.exe[1]: Entering directory `C:/Users/Victor/Documents/CodeLite/Vildhjarta/VildhjartaSTATIC'
codelitegcc g++ -c "C:/Users/Victor/Documents/CodeLite/Vildhjarta/Vildhjarta/Game.cpp" -g -DSFML_STATIC -o ./Debug/Vildhjarta_Game.o -I. -I"C:/SFML 2.0 15 FEB/include"
ar rcus ./Debug/libVildhjartaStatic.a @"VildhjartaStatic.txt" "libsfml-graphics-s-d" "libsfml-window-s-d" "libsfml-audio-s-d" "libsfml-network-s-d" "libsfml-system-s-d" "libsfml-main-d"
ar: libsfml-graphics-s-d: No such file or directory
mingw32-make.exe[1]: *** [Debug/libVildhjartaStatic.a] Error 1
mingw32-make.exe: *** [All] Error 2
VildhjartaStatic.mk:80: recipe for target `Debug/libVildhjartaStatic.a' failed
mingw32-make.exe[1]: Leaving directory `C:/Users/Victor/Documents/CodeLite/Vildhjarta/VildhjartaSTATIC'
Vildhjarta_wsp.mk:4: recipe for target `All' failed
0 errors, 0 warnings
It tells me that it failed and that my graphical libraries is not in the location, but they are it works for dynamic building but not static.

Re: Question regarding making libraries

Posted: Sat Mar 30, 2013 10:43 am
by eranif
Moonkis wrote:1) When making a g++ shared dynamic library I get an *.so file instead of an .dll file and a lib file to link against.
I'v come to terms that you link against an *.so file and then you can rename it and use it as a .dll file for the .exe

Have I grasped this correctly?
Probably a bug in the project template. Just rename it from "project settings -> common -> general" and rename the suffix from .so to .dll
Moonkis wrote:2) Is there an easy way to alternate between an static and shared build? Currently I'm running two projects.
Create two build configurations for the same project. which differs by the project type

http://codelite.org/LiteEditor/ConfigurationManager
Moonkis wrote:Making a dynamic shared library is all good but trying to make a static version of it fails.
Here is the output:
static should no be linked (its useless) - clear all the content in the "Linker" page of the project settings

Eran

Re: Question regarding making libraries

Posted: Sat Mar 30, 2013 3:44 pm
by Moonkis
Problems persist!

Building a static library does work now and I can link to it ( It requires an static link towards SFML in the projects it's being used but I guess that is normal? ).

However, dynamic building does build but linking towards it is just a complete mess. I get an .so file ( which I can't link against ) so I need to rename it to an .dll file which it links against ( ....what? ) then inside my project folder where the .exe lies I need to add the .so file so that it can start......

It's completely backwards! The .dll file should be inside the folder and .so file should be linked but CodeLite/g++ can't find it if it's an .so file. It does link if I rename the .so file into .lib but then again it requires the .so file inside the folder instead of the .dll

Further more why isn't the "template" shared provide me with two files? Both an .dll and an .a file?

Could you shred some light on this?

EDIT: OUTPUT
C:\Windows\system32\cmd.exe /c "mingw32-make.exe -j 4 -e -f "Vildhjarta_wsp.mk""
"----------Building project:[ Vildhjarta_Test - Debug ]----------"
mingw32-make.exe[1]: Entering directory `C:/Users/Victor/Documents/CodeLite/Vildhjarta/Vildhjarta_Test'
codelitegcc g++ -c "C:/Users/Victor/Documents/CodeLite/Vildhjarta/Vildhjarta_Test/main.cpp" -g -O0 -Wall -DSFML_STATIC -o ./Debug/main.o -I. -IC:/Vildhjarta/include -I"C:/SFML 2.0 15 FEB/include"
C:/Users/Victor/Documents/CodeLite/Vildhjarta/Vildhjarta_Test/main.cpp: In function 'int main(int, char**)':
C:/Users/Victor/Documents/CodeLite/Vildhjarta/Vildhjarta_Test/main.cpp:5:14: warning: unused variable 'c' [-Wunused-variable]
g++ -o ./Debug/Vildhjarta_Test @"Vildhjarta_Test.txt" -L. -LC:/Vildhjarta/lib -L"C:/SFML 2.0 15 FEB/lib/Debug/static" -lVildhjartaDynamic -s
c:/mingw-4.7.1/bin/../lib/gcc/mingw32/4.7.1/../../../../mingw32/bin/ld.exe: cannot find -lVildhjartaDynamic
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[1]: *** [Debug/Vildhjarta_Test] Error 1
mingw32-make.exe: *** [All] Error 2
Vildhjarta_Test.mk:80: recipe for target `Debug/Vildhjarta_Test' failed
mingw32-make.exe[1]: Leaving directory `C:/Users/Victor/Documents/CodeLite/Vildhjarta/Vildhjarta_Test'
Vildhjarta_wsp.mk:4: recipe for target `All' failed
0 errors, 1 warnings
I'm sorry if I sound mean but I don't really blame anyone it's just that it gets frustrating, and I'm interested in knowing what I'm doing wrong and if this is how it's suppose to work.

Re: Question regarding making libraries

Posted: Sat Mar 30, 2013 3:54 pm
by eranif
Moonkis wrote:The .dll file should be inside the folder and .so file should be linked but CodeLite/g++ can't find it if it's an .so file
Did you change the output of the project from .so to .dll? read my previous post
Moonkis wrote:It does link if I rename the .so file into .lib but then again it requires the .so file inside the folder instead of the .dll
Changing .dll to .lib is not recommended. You should understand what you are doing
Moonkis wrote:Further more why isn't the "template" shared provide me with two files? Both an .dll and an .a file?
Because its not needed. The .a + .dll is something that Microsoft invented. g++ does not require a .a AND .dll files - it can link directly to the .dll file

Eran

Re: Question regarding making libraries

Posted: Sat Mar 30, 2013 6:39 pm
by Moonkis
Thanks! That made sense, I'll take the information from this topic and search for more information. I'm really grateful for the help you have given me HOWEVER the whole "You should know what you are doing"-attitude puts me off, I'm obviously asking because I want to understand how it works and why it works, googling with few directions doesn't yield good results very often ( I have been googling ).

I'm new, I want to learn and I'm coming from Microsoft Environment which makes gcc/g++ confusing, I am using google but sometimes asking is clearer. I really hope you can understand where I'm coming from and my questions aren't going to be the most intelligent all the time, but trust me I do try to search before posting.

Also instead of saying "you should know" why not add a link that might explain it, or point me towards the general direction? I know you are most likely a busy person but try to remember the time when you were starting out, g++/gcc is not the easiest to grasp.

Kind regards,
Moonkis

Re: Question regarding making libraries

Posted: Sat Mar 30, 2013 7:48 pm
by eranif
Moonkis wrote:Thanks! That made sense, I'll take the information from this topic and search for more information. I'm really grateful for the help you have given me HOWEVER the whole "You should know what you are doing"-attitude puts me off, I'm obviously asking because I want to understand how it works and why it works, googling with few directions doesn't yield good results very often ( I have been googling ).
You should understand that this is a codelite forum. Your questions are not really related to codelite but more of general programming questions.
Moonkis wrote:Also instead of saying "you should know" why not add a link that might explain it, or point me towards the general direction?
You should try to use a C++ forum like http://www.cplusplus.com/forum/

Eran