static library still requires DLL

General questions regarding the usage of CodeLite
Sidar
CodeLite Enthusiast
Posts: 13
Joined: Fri May 04, 2012 6:37 am
Genuine User: Yes
IDE Question: C++
Contact:

static library still requires DLL

Post by Sidar »

I've created my own library and it's pretty much done.
I've compiled the DLL and Static library trough two build configurations. Now I haven't specified any function to be an export or import.
Yet when I test my library I have to link my project against the .a file. But when I try to run my executable it requires the DLL to reside in the same folder as where the exe file is.
There is nothing wrong with this setup, it's exactly how I want it.
However I don't understand where the settings are specified that the my executable still needs to link against a DLL on run-time.

Also:
From a different topic here I learned I should make a .DEF file. And then build the .a from that. Is that the way to link against a DLL at run-time?

Can anyone clarify these two questions? I'm really confused about this.

Edit:

Ok I think my library is an "import library". But then again I never specified any Import or Export classes/functions.
Is the static library by default an import library?
User avatar
eranif
CodeLite Plugin
Posts: 6373
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: static library still requires DLL

Post by eranif »

Sidar wrote:Is the static library by default an import library?
No.

Note: codelite is not a compiler nor a linker

You should understand that if you have in the *same* directory .a and .dll the DLL will get priorty when the linker is resolving symbols.
so if you have:
mylib.dll
mylib.a

and your link line looks like:

-lmylib ==> the linker will pick the .dll

Again, this is not codelite related, but compiler related

Eran
Make sure you have read the HOW TO POST thread
Sidar
CodeLite Enthusiast
Posts: 13
Joined: Fri May 04, 2012 6:37 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: static library still requires DLL

Post by Sidar »

Of course CodeLite is not a compiler. :P
However since Codelite has 3 compile settings : Dynamic library, Static library and Executable for g++/gcc. I wonder what exactly is going on behind the scenes.

My .a and DLL are not in the same folder actually. Well only in my "library" project. But not in my "Test" project and I do not "link" them to my "library" project. I've copied both 2 items into a separate folder.
Like I said I haven't specified any import/export attributes for classes or functions. I just compiled it to a static library. Yet it still requires me to have the dll. If I don't include my dll at my executable it just flat out crashes. If I leave out my .a it won't compile ( but that's obvious though).
I was wondering if anyone could clarify this? Are there any Codelite settings I should know of? Or is there an exception when it comes not not specifying any export/import attributes?
According to the mingw pages I found this:
Building and using a DLL without the dllexport/dllimport attibutes
If you pass the -no-undefined and --enable-runtime-pseudo-reloc options to the linker, you don't have to add dllimport or dllexport attributes to the source code that the DLL is made with ; all functions are imported/exported automatically by default, just like in unices.
But there is all I can find. ( I never specified -no-undefined and --enable-runtime-pseudo-reloc, I just compiled it....)
User avatar
eranif
CodeLite Plugin
Posts: 6373
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: static library still requires DLL

Post by eranif »

Sidar wrote:I wonder what exactly is going on behind the scenes
Nothing is going behind the scenes. codelite prints the compiler output to the 'Build' tab. Maybe if you printed it here we could assist
Sidar wrote:Are there any Codelite settings I should know of?
None

"Dynamic Library" - means, perform a link
"Static Library" - run 'ar' instead of linking

This is the *only* difference between the two types

But again, only be seeing the build log we can assist:
http://forums.codelite.org/viewtopic.php?f=11&t=804

Eran
Make sure you have read the HOW TO POST thread
Sidar
CodeLite Enthusiast
Posts: 13
Joined: Fri May 04, 2012 6:37 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: static library still requires DLL

Post by Sidar »

Here is the output for my static build:
----------Build Started--------
C:\Windows\system32\cmd.exe /c ""mingw32-make.exe" -j -f "ST_wsp.mk""
----------Building project:[ Artemis - Static library ]----------
mingw32-make.exe[1]: Entering directory `C:/Users/Sidar/Documents/Sidar/C++/ST/Artemis'
g++ -c "C:/Users/Sidar/Documents/Sidar/C++/ST/Artemis/src/ComponentType.cpp" -std=c++0x -o ./Release/src_ComponentType.o -I. -I. -Isrc
g++ -c "C:/Users/Sidar/Documents/Sidar/C++/ST/Artemis/src/Component.cpp" -std=c++0x -o ./Release/src_Component.o -I. -I. -Isrc
g++ -c "C:/Users/Sidar/Documents/Sidar/C++/ST/Artemis/src/ComponentTypeManager.cpp" -std=c++0x -o ./Release/src_ComponentTypeManager.o -I. -I. -Isrc
g++ -c "C:/Users/Sidar/Documents/Sidar/C++/ST/Artemis/src/EntitySystem.cpp" -std=c++0x -o ./Release/src_EntitySystem.o -I. -I. -Isrc
g++ -c "C:/Users/Sidar/Documents/Sidar/C++/ST/Artemis/src/SystemBitManager.cpp" -std=c++0x -o ./Release/src_SystemBitManager.o -I. -I. -Isrc
g++ -c "C:/Users/Sidar/Documents/Sidar/C++/ST/Artemis/src/DelayedEntitySystem.cpp" -std=c++0x -o ./Release/src_DelayedEntitySystem.o -I. -I. -Isrc
g++ -c "C:/Users/Sidar/Documents/Sidar/C++/ST/Artemis/src/EntityProcessingSystem.cpp" -std=c++0x -o ./Release/src_EntityProcessingSystem.o -I. -I. -Isrc
g++ -c "C:/Users/Sidar/Documents/Sidar/C++/ST/Artemis/src/Entity.cpp" -std=c++0x -o ./Release/src_Entity.o -I. -I. -Isrc
g++ -c "C:/Users/Sidar/Documents/Sidar/C++/ST/Artemis/src/TagManager.cpp" -std=c++0x -o ./Release/src_TagManager.o -I. -I. -Isrc
g++ -c "C:/Users/Sidar/Documents/Sidar/C++/ST/Artemis/src/World.cpp" -std=c++0x -o ./Release/src_World.o -I. -I. -Isrc
g++ -c "C:/Users/Sidar/Documents/Sidar/C++/ST/Artemis/src/GroupManager.cpp" -std=c++0x -o ./Release/src_GroupManager.o -I. -I. -Isrc
g++ -c "C:/Users/Sidar/Documents/Sidar/C++/ST/Artemis/src/EntityManager.cpp" -std=c++0x -o ./Release/src_EntityManager.o -I. -I. -Isrc
g++ -c "C:/Users/Sidar/Documents/Sidar/C++/ST/Artemis/src/DelayedEntityProcessingSystem.cpp" -std=c++0x -o ./Release/src_DelayedEntityProcessingSystem.o -I. -I. -Isrc
g++ -c "C:/Users/Sidar/Documents/Sidar/C++/ST/Artemis/src/SystemManager.cpp" -std=c++0x -o ./Release/src_SystemManager.o -I. -I. -Isrc
ar rcus ./Release/artemis.a @"C:\Users\Sidar\Documents\Sidar\C++\ST\Artemis\Artemis.txt"
mingw32-make.exe[1]: Leaving directory `C:/Users/Sidar/Documents/Sidar/C++/ST/Artemis'
mingw32-make.exe[1]: Entering directory `C:/Users/Sidar/Documents/Sidar/C++/ST/Artemis'
Executing Post Build commands ...
move "C:\Users\Sidar\Documents\Sidar\C++\ST\Artemis"\Release\artemis.a "C:\Users\Sidar\Documents\Sidar\C++\ST\Artemis"\bin
1 bestand(en) zijn verplaatst.
Done
mingw32-make.exe[1]: Leaving directory `C:/Users/Sidar/Documents/Sidar/C++/ST/Artemis'
----------Build Ended----------
0 errors, 0 warnings
Note: I did not create a static project from the project template. I simply looked at the settings and copied them over to my new build configuration. Perhaps i'm missing something?
User avatar
eranif
CodeLite Plugin
Posts: 6373
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: static library still requires DLL

Post by eranif »

I actually need to see the output of the 'link' of your executable.
Also: what is the idea of copying the .a to the 'bin' directory? by convention, 'bin' is for executables and for .dll files only.
The executable does not use the .a at runtime...


Eran
Make sure you have read the HOW TO POST thread
Sidar
CodeLite Enthusiast
Posts: 13
Joined: Fri May 04, 2012 6:37 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: static library still requires DLL

Post by Sidar »

Also: what is the idea of copying the .a to the 'bin' directory? by convention, 'bin' is for executables and for .dll files only.
The executable does not use the .a at runtime...
I've set it in my DLL build configuration to a lib folder. These settings for the static build are outdated.

Im not sure what you mean by output link( sorry for being so anal ) can you direct me where I can find it?
Post Reply