Linker Error with External Lib

BlitzMax Forums/BlitzMax Programming/Linker Error with External Lib

Gabriel(Posted 2007) [#1]
This is going off topic from the Vista/MinGW thread now, so I'll post separately.

I've got a MinGW Static Library, which references a MinGW Dynamic Library. The Dynamic Library has a .dll and a .a and the static library, just a .a.

The Static Library was built with the .a from the dynamic library included in the linker options.

I get undefined reference to blah::blah for every command in the dynamic library. Why, and how can I fix it?


Gabriel(Posted 2007) [#2]
Anyone got any ideas? Since I can't get BMax to compile a module with GCC at all, this is the only way I have left to build the TV3D and HGE modules.


Dreamora(Posted 2007) [#3]
does your static library internally import the .a of the dynamic library at all? or better include the header file of the dynamic library? otherwise the functionality is nowhere defined and won't work.


Gabriel(Posted 2007) [#4]
My Static Library has a Dev C++ Project file, and the project imports the .a of the dynamic library in the linker options. This is all I have to do to compile a standalone GUI app in DevC++ so I thought this would be fine for my static library too.


errno!(Posted 2007) [#5]
even if a lib you use imports the .a file it's self, you usually have to manually import it in blitz too.

if the depnded on lib is called libgab.a for example, add this to your imports

import "libgab.a"

blitz will recognigze it as a lib and import it as you'd expect.
-edit- you have to copy the the .a file to your project's folder where it compiles from.


Gabriel(Posted 2007) [#6]
Yes, I import the lib into the BlitzMax project as well, but I don't think that's where the linking error is. It reports the name of my CPP file ( the base file of the static lib ) as being the source of the linker errors, so I think it's the static lib that can't see the functions, not the module.


Dabz(Posted 2007) [#7]
Any chance you could re-indroduce the problem you are having gabs in a example, with roughly everything you have (bmx files, lib file and dll file)

It would be a lot betterer to play around than trying to guess! ;)

Dabz


Gabriel(Posted 2007) [#8]
Well there's about 100 files, so it's a bit OTT to do that.

Essentially :

Dynamic Lib - Contains lots of functions in classes. (Eg: class1->Function1(), class2->Function1(), class2->Function2(), etc )

Static Lib - Links to Dynamic Lib
Exports lots of Functions in CDECL format
Calls functions in Dynamic Library

Blitzmax Module - Imports Dynamic Lib.
Imports Static Lib.
Calls Functions in Static Lib.

And when I compile the module, I get several hundred undefined references to the class and function names in the dynamic library. The errors are all reported in the static library.


Dabz(Posted 2007) [#9]
It seems a bit of a mare, could you try CORE_EXPORT after the class keyword:-

class CORE_EXPORT GabsClass

in your lib sources and see if it builds and works?

Baring in mind, this is just from research on the net regarding linking to DLL's that contain classes.

Still, I've tried! ;)

Dabz


Dreamora(Posted 2007) [#10]
Hmm class functions are a little bit different than regular ones ... cause normally you would enclose the code in export "C" which makes sure it will work.

If you use objects thought, you might want to use extern types and declare the whole objects there to prevent this kind of error (unless the lib you import already offers plain function access but I do not assume so as we are talking of TV3D most likely)


Gabriel(Posted 2007) [#11]
Dabs: Thanks. There's no problem exporting the classes, the headers are already set up with CORE_EXPORT or EXPORTCLASS or something like that. I can link to them just fine if it's built as a single BMax module which imports the C code instead of compiling the C code as a static library. I gather it must be the way I'm linking in the Dev C++ project which is causing the problem.

Dreamora: You can't link to libraries by Externing the types, that only works with classes with virtual methods, and that's not what TV has. The whole purpose of the static library is to write plain functions which call the class functions. It's the static library which can't see the classes, not the BMAX module.