Solved

link .lib files with gcc

Posted on 2004-10-06
13
832 Views
Last Modified: 2007-12-19
I have to link a .lib file using gcc for PalmOS (m68k-palmos-gcc) but i think it is the same with gcc.
I don´t know how to link it so te compiler tells me udefined reference for all Procedures that exist in muy .lib file.
Do anyone know how to link a .lib file?
Thanks
0
Comment
Question by:martin11_ar
  • 6
  • 5
13 Comments
 
LVL 11

Expert Comment

by:avizit
ID: 12240893
You have to tell the compiler the location of the .lib file and also have to mention it using -l

as "-lm" for the math library

check


http://vergil.chemistry.gatech.edu/resources/programming/c-tutorial/libraries.html


excerpts

# When linking your program to the libraries, make sure you specify where the library can be found:

  gcc -o foo -L. -lmylib foo.o

The -L. piece tells gcc to look in the current directory in addition to the other library directories for finding libmylib.a.

0
 

Author Comment

by:martin11_ar
ID: 12241344
ok , but i have a .lib library and the -l option is for .a libraries. The linker tells me that the file doesn´t exist, i think for that reason.
I read that exists an application to convert .lib files into .a files but i can´t find it
Do you know where can i download it (for windows)?
0
 
LVL 2

Expert Comment

by:aleric
ID: 12244569
It might be as simple as renaming (copying) the .lib
file to a .dll.a name:

cp foo.lib foo.dll.a

Then using -lfoo will find it.

However - that still might not work, because gcc
uses slightly different symbols for stdcall functions.
Just try it - if it doesn't work then tell me WHAT doesn't
work (I want to see the actual errors) I'll add more
directions.
0
 

Author Comment

by:martin11_ar
ID: 12248174
I tried:

m68k-palmos-gcc pruebascanner.cpp -l ScanMgr.dll.a

m68k-palmos-gcc pruebascanner.cpp -l ScanMgr

m68k-palmos-gcc pruebascanner.cpp -l "complete path\ScanMgr.dll.a"

m68k-palmos-gcc pruebascanner.cpp -l "complete path\ScanMgr"

In all cases the compiler says:

/prc-tools/H-i586-cygwin32/m68k-palmos/bin/ld: cannot open -lScanMgr.dll.a: No such file o directory

where say ScanMgr.dll.a change for the correspondent -l file on command line
0
 
LVL 2

Expert Comment

by:aleric
ID: 12248353
Assuming that ScanMgr.dll.a exists and is in fact
a copy of the .lib file and is readable and executable
(not sure if that is really needed actually), then you
should do the following:

m68k-palmos-gcc pruebascanner.cpp -L"complete path" -lScanMgr

This should look for ScanMgr.dll.a in "complete path".
Note that "complete path" is only a directory, it does not
include the name of the library of course.

0
 

Author Comment

by:martin11_ar
ID: 12249886
Again in all cases the compiler says:

/prc-tools/H-i586-cygwin32/m68k-palmos/bin/ld: cannot open -lScanMgr.dll.a: No such file o directory

I remember you that i´m compiling no Windows NT. I´m using m68k-palmos-gcc for windows which use cygwin.dll
It means that i don´t have readable and executable options for files.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Expert Comment

by:aleric
ID: 12250163
What do you mean in _all_ cases?  I just gave one command line.
Can you repeat (copy&paste) that command line along with
everything that is being output, when doing:

m68k-palmos-gcc pruebascanner.cpp -L"complete path" -lScanMgr -v

Note the added -v and fix the path of course.  Also show me the
output of:

ls -l "complete path" /ScanMgr *

or whatever is the equivalent of that on windows NT. I want to see
with own eyes that that file actually exists at that place.


0
 

Author Comment

by:martin11_ar
ID: 12250873
Ok, the command line:

C:\Archivos de programa\InfomercSA\FORMBY\bin>m68k-palmos-gcc pruebascanner.cpp
-L "c:\archivos de programa\infomercsa\formby\bin" -lScanmgr -v
Reading specs from /prc-tools/H-i586-cygwin32/lib/gcc-lib/m68k-palmos/2.95.2-kgp
d/specs
gcc version 2.95.2-kgpd 19991024 (release)
 /prc-tools/H-i586-cygwin32/lib/gcc-lib/m68k-palmos/2.95.2-kgpd/cpp.exe -lang-c+
+ -v -D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=95 -D__cplusplus -Dm68000 -Dmc68
000 -Dm68k -D__palmos__ -D__m68000__ -D__mc68000__ -D__m68k__ -D__palmos__ -D__m
68000 -D__mc68000 -D__m68k -Asystem(palmos) -Acpu(m68k) -Amachine(pilot) -D__EXC
EPTIONS -Dmc68000 -D__mc68000 -D__mc68000__ -isystem /PalmDev/include -isystem /
PalmDev/sdk/include/Core/System -isystem /PalmDev/sdk/include/Core/UI -isystem /
PalmDev/sdk/include -isystem /PalmDev/sdk/include/Core -isystem /PalmDev/sdk/inc
lude/Core/Hardware -isystem /PalmDev/sdk/include/Core/System/Unix -remap pruebas
canner.cpp C:\TEMP/cctODilx.ii
GNU CPP version 2.95.2-kgpd 19991024 (release) (68k, Motorola syntax)
#include "..." search starts here:
#include <...> search starts here:
 /PalmDev/include
 /PalmDev/sdk/include/Core/System
 /PalmDev/sdk/include/Core/UI
 /PalmDev/sdk/include
 /PalmDev/sdk/include/Core
 /PalmDev/sdk/include/Core/Hardware
 /PalmDev/sdk/include/Core/System/Unix
 /prc-tools/H-i586-cygwin32/lib/gcc-lib/m68k-palmos/2.95.2-kgpd/include
 /prc-tools/H-i586-cygwin32/lib/gcc-lib/m68k-palmos/2.95.2-kgpd/../../../../m68k
-palmos/include
End of search list.
The following default directories have been omitted from the search path:
 /prc-tools/H-i586-cygwin32/lib/gcc-lib/m68k-palmos/2.95.2-kgpd/../../../../../i
nclude/g++-3
 /prc-tools/H-i586-cygwin32/lib/gcc-lib/m68k-palmos/2.95.2-kgpd/../../../../m68k
-palmos/sys-include
End of omitted list.
 /prc-tools/H-i586-cygwin32/lib/gcc-lib/m68k-palmos/2.95.2-kgpd/cc1plus.exe C:\T
EMP/cctODilx.ii -fpic -msoft-float -m68000 -Wno-multichar -quiet -dumpbase prueb
ascanner.cc -version -o C:\TEMP/ccfbjRHC.s
GNU C++ version 2.95.2-kgpd 19991024 (release) (m68k-palmos) compiled by GNU C v
ersion egcs-2.91.57 19980901 (egcs-1.1 release).
 /prc-tools/H-i586-cygwin32/m68k-palmos/bin/as.exe -mno-68881 -m68000 -l -o C:\T
EMP/cctYOHdw.o C:\TEMP/ccfbjRHC.s
 /prc-tools/H-i586-cygwin32/lib/gcc-lib/m68k-palmos/2.95.2-kgpd/collect2.exe -L/
PalmDev/lib/m68k-palmos-coff -L/PalmDev/sdk/lib/m68k-palmos-coff --embedded-relo
cs -N -dy -T /prc-tools/H-i586-cygwin32/lib/gcc-lib/m68k-palmos/2.95.2-kgpd/pilo
t.ld /prc-tools/H-i586-cygwin32/m68k-palmos/lib/crt0.o -L c:\archivos de program
a\infomercsa\formby\bin -L/prc-tools/H-i586-cygwin32/lib/gcc-lib/m68k-palmos/2.9
5.2-kgpd -L/prc-tools/H-i586-cygwin32/m68k-palmos/lib C:\TEMP/cctYOHdw.o -lScanm
gr -lcrt -lgcc -lc -lcrt -lgcc
C:\TEMP/cctYOHdw.o(.text+0x1420):pruebascanner.cpp: undefined reference to `ScanIsPalmSymbolUnit(void)'
C:\TEMP/cctYOHdw.o(.text+0x142a):pruebascanner.cpp: undefined reference to `ScanOpenDecoder(void)'
C:\TEMP/cctYOHdw.o(.text+0x1432):pruebascanner.cpp: undefined reference to `ScanCmdScanEnable(void)'
C:\TEMP/cctYOHdw.o(.text+0x143a):pruebascanner.cpp: undefined reference to `ScanSetTriggeringModes(unsigned short)'
C:\TEMP/cctYOHdw.o(.text+0x1448):pruebascanner.cpp: undefined reference to `ScanSetBarcodeEnabled(tagBarType, unsigned char)'
C:\TEMP/cctYOHdw.o(.text+0x1456):pruebascanner.cpp: undefined reference to `ScanSetBarcodeEnabled(tagBarType, unsigned char)'
C:\TEMP/cctYOHdw.o(.text+0x1464):pruebascanner.cpp: undefined reference to `ScanSetBarcodeEnabled(tagBarType, unsigned char)'
C:\TEMP/cctYOHdw.o(.text+0x1472):pruebascanner.cpp: undefined reference to `ScanSetBarcodeEnabled(tagBarType, unsigned char)'
C:\TEMP/cctYOHdw.o(.text+0x1480):pruebascanner.cpp: undefined reference to `ScanSetBarcodeEnabled(tagBarType, unsigned char)'
C:\TEMP/cctYOHdw.o(.text+0x148e):pruebascanner.cpp: more undefined references to
 `ScanSetBarcodeEnabled(tagBarType, unsigned char)' follow
C:\TEMP/cctYOHdw.o(.text+0x14a4):pruebascanner.cpp: undefined reference to `ScanCmdSendParams(tagBeepType)'
C:\TEMP/cctYOHdw.o(.text+0x14b8):pruebascanner.cpp: undefined reference to `ScanGetDecodedData(tagMESSAGE *)'
C:\TEMP/cctYOHdw.o(.text+0x15ec):pruebascanner.cpp: undefined reference to `ScanCmdScanDisable(void)'
C:\TEMP/cctYOHdw.o(.text+0x15f0):pruebascanner.cpp: undefined reference to `ScanCloseDecoder(void)'
collect2: ld returned 1 exit status

Equivalent to ls on Windows NT

C:\Archivos de programa\InfomercSA\FORMBY\bin>dir Scanmgr*
 El volumen de la unidad C no tiene etiqueta.
 El número de serie del volumen es: 3B46-1AED

 Directorio de C:\Archivos de programa\InfomercSA\FORMBY\bin

01/10/04  15.46                  7.930 ScanMgr.h
01/10/04  15.45                 10.528 ScanMgrDef.h
01/10/04  15.46                  2.904 ScanMgrStruct.h
17/03/99  13.53                 12.508 ScanMgr.lib
17/03/99  13.53                 12.508 ScanMgr.dll.a
               5 archivos         46.378 bytes
                             70.877.184 bytes libres

0
 

Author Comment

by:martin11_ar
ID: 12321130
Can you help me?

I did:

m68k-palmos-gcc pruebascanner.cpp -L"complete path" -lScanMgr -v

And i wrote the output
0
 
LVL 2

Expert Comment

by:aleric
ID: 12334766
A few observations:

1) You didn't get
/prc-tools/H-i586-cygwin32/m68k-palmos/bin/ld: cannot open -lScanMgr.dll.a: No such file o directory
Like you said in your post of 10/07/2004 05:30PM CEST. Instead I see that the error is:
C:\TEMP/cctYOHdw.o(.text+0x1420):pruebascanner.cpp: undefined reference to `ScanIsPalmSymbolUnit(void)'

2) The final linker uses:
-L c:\archivos de programa\infomercsa\formby\bin
-L/prc-tools/H-i586-cygwin32/lib/gcc-lib/m68k-palmos/2.95.2-kgpd
-L/prc-tools/H-i586-cygwin32/m68k-palmos/lib
Apparently in one of those directories it finds the library(?).
The only directory that makes sense to every find it however is
c:\archivos de programa\infomercsa\formby\bin
(Ugh, I hate that confusing lower/upper case mixup), which you listed:
Directorio de C:\Archivos de programa\InfomercSA\FORMBY\bin

01/10/04  15.46                  7.930 ScanMgr.h
01/10/04  15.45                 10.528 ScanMgrDef.h
01/10/04  15.46                  2.904 ScanMgrStruct.h
17/03/99  13.53                 12.508 ScanMgr.lib
17/03/99  13.53                 12.508 ScanMgr.dll.a
               5 archivos         46.378 bytes
                             70.877.184 bytes

Try removing ScanMgr.lib there, just to be sure.
And try renaming ScanMgr.dll.a to libScanMgr.dll.a

Make sure that have gotten rid of the error
"-lScanMgr.dll.a: No such file o directory"
and instead get a
"undefined reference to ..."
that is progress.  Make sure you get that progress
because it files the *ScanMgr* file in
C:\Archivos de programa\InfomercSA\FORMBY\bin
by removing it and adding it again, so that you are
sure that that files causes the improvement: then you
are sure that at least it is found and used.





0
 
LVL 2

Expert Comment

by:aleric
ID: 12334791
Replace that last alinea with this:

Make sure that you have gotten rid of the error
"-lScanMgr: No such file or directory"
and instead get _only_
"undefined reference to ..."
error.  That would be progress.  Make sure you get rid of
the former error because it finds  the *ScanMgr* file in
C:\Archivos de programa\InfomercSA\FORMBY\bin
,by removing the libScanMgr.dll.a file and adding it again,
and observing the change in the eror, so that you are
sure that it is that file that causes the improvement: then you
are sure that at least it is found and used.  After that
we can tackle the undefined symbols...
0
 
LVL 2

Accepted Solution

by:
aleric earned 125 total points
ID: 12634996
Imho, it was abandoned by the author.  He never replied to my last comments.
Rereading this, he started with asking the wrong question and his main
problem is that he simply has no idea what he is doing (ie, doesn't know
what the commandline options of gcc are, what -L does etc etc).
I jumped in because I have special expertise in solving complicated
problems related to mixing microsoft (.lib) and gcc libraries.  However,
that is a million times behond the level of understanding that the author
reached at the moment. I can't say I am really interested in this thread
anymore therefore (however, I don't think I said anything wrong either -
it just got a bit tiresome and boring).
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now