Code::Blocks Forums

User forums => Help => Topic started by: w2vy on March 17, 2006, 03:19:05 pm

Title: Adding External Library to HelloWorld C++
Post by: w2vy on March 17, 2006, 03:19:05 pm
I am trying to use a Cypress USB Library and I am having linker problems.

It appears to be a Name Mangling problem.

Here is my build log:

Code
-------------- Build: default in HelloWorld ---------------
mingw32-g++.exe -LC:\MinGW\lib  -o HelloWorld.exe .objs\main.o    W:\tom\BORGPC\CyAPI.lib
.objs\main.o: In function `Z41__static_initialization_and_destruction_0ii':
W:/tom/prj/HelloWorld/main.cpp:5: undefined reference to `CCyUSBDevice::CCyUSBDevice(void*, _GUID, int)'
W:/tom/prj/HelloWorld/main.cpp:5: undefined reference to `CCyUSBDevice::~CCyUSBDevice
()'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 2 seconds)
2 errors, 0 warnings

I created the project using the Console Application C++ Template which works fine before I
added the #include for the library. (Which has a handful of class definitions and works fine in VC++ 6.0 and borland from talking to other developers)

I also have attached the project directory.

I think it is a mangling problem because the error does not change if I remove the library
from the linker library list...

I am kinda surprised that the extern gcc created is class::function...
but then again I am new at this...

Here's HelloWorld.c (it's in the archive too)
Code
#include <iostream>
#include <windows.h>

#include "cyAPI.h"
CCyUSBDevice USBDevice;

int main()
{
    int counts;

//    counts = USBDevice.DeviceCount();
std::cout << "Hello world!" << std::endl;
return counts;
}
---
Ah yes... critical details...
I am using nightly build:
Version 1.0 revision 2199 (gcc 3.4.4 Windows/unicode, build: Mar 15 2006 20:19:14)

mingw
binutils-2.16.91-20050827-1.tar.gz
gcc-core-3.4.4-20050522-1.tar.gz
gcc-g++-3.4.4-20050522-1.tar.gz
mingw-runtime-3.9.tar.gz
mingw-utils-0.3.tar.gz
mingw32-make-3.80.0-3.tar.gz
w32api-3.5.tar.gz

Which is basically the mingw install from the wiki

tom

[attachment deleted by admin]
Title: Re: Adding External Library to HelloWorld C++
Post by: Michael on March 17, 2006, 04:50:31 pm
Hello,

I have given it a try and I have the following comments/remarks :):


You would may be take into consideration to update your GCC and win32api header files (may be binutils files too).

Best wishes,
Michael
Title: Re: Adding External Library to HelloWorld C++
Post by: w2vy on March 17, 2006, 05:19:00 pm
  • Your project is not a C project, but a C++ project
  • Your project compiles fine with Visual Studio .NET 2003 (I am not really surprised :))
  • Your C::B project compiles quite fine with M$ Toolkit .NET 2003. Anyway, you have to add the windows libraries in the linker tab (in Visual Studio .NET, they are inherited)
  • Your project does not compile with GCC 4.1.0. The cause is IMHO the library. If I am not wrong, it is a static library compiled with Visual Studio (VC6) and it is not compatible with GCC. You should rebuild your library by using GCC (you will have then a static .a library).

You would may be take into consideration to update your GCC and win32api header files (may be binutils files too).

Best wishes,
Michael


Yes it is C++.

It is a vendor supplied library... so I may be forced into using M$ Toolkit

Oh wait, maybe I can still use C::B (I had a hard time getting visual studio out of my way)
Being new to both tool chains... I am not sure what libs you added where...

As far as updating GCC, w32api and binutils... It won't change anything... just be more current...
(I thought what I downloaded *was* current LOL sigh... i'll be happy when RC3 is out)

tom
Title: Re: Adding External Library to HelloWorld C++
Post by: Michael on March 17, 2006, 05:31:38 pm
It is a vendor supplied library... so I may be forced into using M$ Toolkit

If you have a shared version of the library, then you can still use the dll and generate an import library for GCC. But I am not sure if the license will allow this. You will have to check carefully the license before.

Oh wait, maybe I can still use C::B (I had a hard time getting visual studio out of my way)
Being new to both tool chains... I am not sure what libs you added where...

I will attach a .7z copy of your project file (modified version). What I have is to put the .h file of the library into an include directory and the library into a lib directory.

As far as updating GCC, w32api and binutils... It won't change anything... just be more current...
(I thought what I downloaded *was* current LOL sigh... i'll be happy when RC3 is out)

Yes, of course, but you will have an updated MinGW version :).

To be honest, I am happy with building C::B by myself  :).

Best wishes,
Michael


[attachment deleted by admin]
Title: Re: Adding External Library to HelloWorld C++
Post by: MortenMacFly on March 18, 2006, 04:56:17 pm
Code
-------------- Build: default in HelloWorld ---------------
mingw32-g++.exe -LC:\MinGW\lib  -o HelloWorld.exe .objs\main.o    W:\tom\BORGPC\CyAPI.lib
I didn't understand whether the problem is already solved but please allow me this remark:
It looks you are using a MSVC library (.lib) with the MinGW/GCC compiler. This won't work. Eigther you use the MSVC toolkit to link agains a MSVC library or you convert the *.lib into a *.a (the static library "format" of MinGW/GCC) which should be possible. I remember that I posted how to do so for the python library in the forum...
With regards, Morten.
Title: Re: Adding External Library to HelloWorld C++
Post by: TDragon on March 18, 2006, 09:09:03 pm
It looks you are using a MSVC library (.lib) with the MinGW/GCC compiler. This won't work.
Actually, the GCC linker can interpret .lib files. This only works to a certain extent, because MSVC DLL symbols usually can't be resolved correctly, but purely static libraries can usually be made to work -- SDL_ttf being one instance where I've done so.