User forums > Help
Adding External Library to HelloWorld C++
w2vy:
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
--- End code ---
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;
}
--- End code ---
---
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]
Michael:
Hello,
I have given it a try and I have the following comments/remarks :):
* 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
w2vy:
--- Quote from: Michael on March 17, 2006, 04:50:31 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
--- End quote ---
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
Michael:
--- Quote from: w2vy on March 17, 2006, 05:19:00 pm ---It is a vendor supplied library... so I may be forced into using M$ Toolkit
--- End quote ---
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.
--- Quote from: w2vy on March 17, 2006, 05:19:00 pm ---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...
--- End quote ---
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.
--- Quote from: w2vy on March 17, 2006, 05:19:00 pm ---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)
--- End quote ---
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]
MortenMacFly:
--- Quote from: w2vy on March 17, 2006, 03:19:05 pm ---
--- Code: ----------------- Build: default in HelloWorld ---------------
mingw32-g++.exe -LC:\MinGW\lib -o HelloWorld.exe .objs\main.o W:\tom\BORGPC\CyAPI.lib
--- End code ---
--- End quote ---
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.
Navigation
[0] Message Index
[#] Next page
Go to full version