• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1335
  • Last Modified:

link .lib files with gcc

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?
  • 6
  • 5
1 Solution
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




# 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.

martin11_arAuthor Commented:
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)?
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

martin11_arAuthor Commented:
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
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.

martin11_arAuthor Commented:
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.
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.

martin11_arAuthor Commented:
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
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:
End of search list.
The following default directories have been omitted from the search path:
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

martin11_arAuthor Commented:
Can you help me?

I did:

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

And i wrote the output
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
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.

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...
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).
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now