link .lib files with gcc

Posted on 2004-10-06
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?
Question by:martin11_ar
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
LVL 11

Expert Comment

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



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


Author Comment

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)?

Expert Comment

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

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

Expert Comment

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.


Author Comment

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.

Expert Comment

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.


Author Comment

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


Author Comment

ID: 12321130
Can you help me?

I did:

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

And i wrote the output

Expert Comment

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


Expert Comment

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

Accepted Solution

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Socket Programming (Unix) 8 153
Dynamically allocate memory 9 70
Using Diagnostic tools in VS2015: Unresoved allocations 19 126
learn programming 8 74
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

697 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