LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-22-2003, 11:34 AM   #1
jpbarto
Senior Member
 
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251

Rep: Reputation: 45
Link DLL with C code on Win32 (CygWin)


Under CygWin I have an API for some hardware I have. This API came from the vendor and contains a DLL, a .h file and a .lib file. I took some of their example code, ported it from VC source to gcc source. I've created a .o object of the example C code but when I go to link the two (gcc api.dll example.o -o example) I some undefined references for the functions contained in the dll... what do I have to do to get these two to link up?

thanks in advance,
jpbarto
 
Old 10-23-2003, 10:14 AM   #2
jpbarto
Senior Member
 
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251

Original Poster
Rep: Reputation: 45
ok, some advancement has been made... although not much.
Again this environment is under Cygwin / Win2K using the latest cygwin software (just installed it onto a new laptop). And as I've said I have three files an api.h, api.dll and an api.lib. Most of the tutorials I have found have proved innefective as they depend upon dll's that have not been stripped. Well guess what, api.dll has been stripped thus I was not able to create a .def file from it or subsequently create a library file (for ld with gcc). However the api.lib file was NOT stripped and I was able (using nm) to get the symbols from it. I have been able to create an api.a library file with it. However when I go to link my C code with it (gcc -o demo demo.o api.a) I get all 4 complaints about undefined references (one for each function in the api library I'm trying to use).

Why is it that gcc cannot reference the library api.a???

jpbarto
 
Old 10-23-2003, 02:18 PM   #3
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
The order of object files and libraries on the gcc command line is significant.

What is the exact command you're trying to use?

Quote:
+ Arguments of the form -lx cause the linker to search the
library libx.sl or libx.a in an attempt to resolve currently
unresolved external references. Because a library is searched
when its name is encountered, placement of a -l is
significant. If a file contains an unresolved external
reference, the library containing the definition must be
placed after the file on the command line. See ld(1) for
further details.
 
Old 10-23-2003, 03:27 PM   #4
jpbarto
Senior Member
 
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251

Original Poster
Rep: Reputation: 45
gcc -o demo demo.o api.a

are you saying that perhaps listing the api.a first may help?

I'll give it a shot.
 
Old 10-23-2003, 03:30 PM   #5
jpbarto
Senior Member
 
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251

Original Poster
Rep: Reputation: 45
tried the following:

gcc -L./ -o demo api.a demo.o

same errors still no joy
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting Windows DLL code to Linux shared library DavidW567 Programming 7 07-27-2010 09:15 AM
cygexpat-0.dll problems in cygwin aneeshm Linux - General 1 05-13-2005 09:03 AM
Convert a dll code to linux EvilLinux Programming 5 12-08-2004 10:51 AM
Can I access a Windows DLL directly from Linux code? Silverjam Linux - Software 3 07-10-2004 10:46 PM
How does VC link a dll created by cygwin? chuanyung Programming 1 02-25-2004 01:06 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration