By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,389 Members | 1,881 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,389 IT Pros & Developers. It's quick & easy.

undefined reference to `OpenPrinterA@12'

P: n/a
When trying to compile this program

-----------------------------------------
#include <windows.h>
#include <winspool.h>

main() {

LPHANDLE printer;

OpenPrinter("sdsd",printer,NULL);
}
-----------------------------------------

with gcc I get the following error message: undefined reference to
`OpenPrinterA@12'

What am I doing wrong? OpenPrinter is defined in winspool.h so why is it not
found?

regards
Jimmy
Nov 14 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Jimmy Rasmussen <ji****@get2net.dk> wrote:
When trying to compile this program -----------------------------------------
#include <windows.h>
#include <winspool.h> main() { LPHANDLE printer; OpenPrinter("sdsd",printer,NULL);
}
----------------------------------------- with gcc I get the following error message: undefined reference to
`OpenPrinterA@12' What am I doing wrong? OpenPrinter is defined in winspool.h so why is it not
found?


What you're getting here isn't a compiler but a linker error. And that
means that you need to link the library that defines the OpenPrinter()
function (whatever it does) to your program - the header file only
tells the compiler how the function is to be used but does not contain
any code for it.
Regards, Jens
--
\ Jens Thoms Toerring ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.physik.fu-berlin.de/~toerring
Nov 14 '05 #2

P: n/a
Jimmy Rasmussen wrote:
When trying to compile this program

-----------------------------------------
#include <windows.h> Not standard
#include <winspool.h> Not standard
main() {
must be
int main(int argc, char **argv)
or
int main(void)

LPHANDLE printer;
Not standard
OpenPrinter("sdsd",printer,NULL); Not standard
}
main() must return an integer
-----------------------------------------

with gcc I get the following error message: undefined reference to
`OpenPrinterA@12' What am I doing wrong? OpenPrinter is defined
no, it is not defined, it is *declared*.
in winspool.h so why is it not
found?


How do you expect your linker to resolve a symbol if you do not link
with the approriate object code (ie : object file or library) ? Read
your linker manual to know how to tell it to link to a specific lib, and
read your OS/API/Lib/Whatsoever doc to know which lib to link to.

Bruno

Nov 14 '05 #3

P: n/a

Since winspool.h is found in the same directory as stdio.h etc., I assumed
that the code was part of the standard library of my compiler. If this is
the case, is gcc not supposed to find the corresponding object files itself
? The functions mentioned in the windows.h file (that you said was not
standard) can be used without mentioning any libraries to the linker. I've
tried to explicitly tell gcc about the library (I found a file called
libwinspool.a) like this

gcc Printcharger.c -L "d:\Dev-C++\lib\" -l winspool

but with the same result. Maybe gcc (or my head) has not been properly
installed

"Bruno Desthuilliers" <bd***********@removeme.free.fr> wrote in message
news:3f**********************@news.free.fr...
Jimmy Rasmussen wrote:
When trying to compile this program

-----------------------------------------
#include <windows.h>

Not standard
#include <winspool.h>

Not standard
main() {


must be
int main(int argc, char **argv)
or
int main(void)

LPHANDLE printer;


Not standard
OpenPrinter("sdsd",printer,NULL);

Not standard
}


main() must return an integer
-----------------------------------------

with gcc I get the following error message: undefined reference to
`OpenPrinterA@12'

What am I doing wrong? OpenPrinter is defined


no, it is not defined, it is *declared*.
in winspool.h so why is it not
found?


How do you expect your linker to resolve a symbol if you do not link
with the approriate object code (ie : object file or library) ? Read
your linker manual to know how to tell it to link to a specific lib, and
read your OS/API/Lib/Whatsoever doc to know which lib to link to.

Bruno

Nov 14 '05 #4

P: n/a
On Sat, 13 Dec 2003 16:15:50 +0100, in comp.lang.c , "Jimmy Rasmussen"
<ji****@get2net.dk> wrote:
When trying to compile this program
snip windows code
with gcc I get the following error message: undefined reference to
`OpenPrinterA@12'

What am I doing wrong?
You're asking in the wrong group for starters. This is not a windows
programming group.
OpenPrinter is defined in winspool.h so why is it not
found?


the header doesn't define the function, only declare it. The actual
definition is probably in some library or other which you forgot to
link with.
By the way, did you notice that your function name is not the same as
that which gcc complains about?
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 14 '05 #5

P: n/a
"Jimmy Rasmussen" <ji****@get2net.dk> wrote in
news:3f***********************@nntp04.dk.telia.net :
Since winspool.h is found in the same directory as stdio.h etc., I
assumed that the code was part of the standard library of my compiler.
Standard libraries are not compiler specific (you could say that's why they
are called standard).
If this is the case, is gcc not supposed to find the corresponding
object files itself ?
Every compiler has a default set of libraries that it links against. If you
want to link against other libraries, you need to specify them.
The functions mentioned in the windows.h file (that you said was not
standard) can be used without mentioning any libraries to the linker.
windows.h is Windows specific. Its contents are not defined by the ANSI/ISO
standard C language. Hence, it is off-topic in this newsgroup.

It looks like OpenPrinter is not in the default set of libraries that are
linked against.
I've tried to explicitly tell gcc about the
library (I found a file called libwinspool.a) like this

gcc Printcharger.c -L "d:\Dev-C++\lib\" -l winspool
In some shells, you'd never be able to run that command on the command
line. In addition, lose the space between -l and winspool.
but with the same result. Maybe gcc (or my head) has not been properly
installed.


It's the latter. You are also in the wrong newsgroup. Next time, you should
at least read your compiler's documentation.

$ cat PrintCharger.c
#include <windows.h>
#include <winspool.h>

int main(void) {
LPHANDLE printer;
OpenPrinter("sdsd",printer,NULL);
return 0;
}

$ gcc -Wall PrintCharger.c -o PrintCharger.exe -lwinspool

--
A. Sinan Unur
as**@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uc*@ftc.gov
Nov 14 '05 #6

P: n/a
"Jimmy Rasmussen" <ji****@get2net.dk> wrote:
Since winspool.h is found in the same directory as stdio.h etc., I
assumed that the code was part of the standard library of my compiler.
If this is the case, is gcc not supposed to find the corresponding
object files itself?
No, this code is not part of the standard library, and on most implementations
it must be specifically linked in. In fact, on many implementations the <math.h>
section of the standard library is not even linked by default, you must link the
libm.a file by using an option like -lm!
The functions mentioned in the windows.h file (that you said was not
standard) can be used without mentioning any libraries to the linker.
I've tried to explicitly tell gcc about the library (I found a file
called libwinspool.a) like this

gcc Printcharger.c -L "d:\Dev-C++\lib\" -l winspool

but with the same result. Maybe gcc (or my head) has not been
properly installed


Perhaps so. Your file compiles fine when I use -l winspool:

C:\docs\prog\c>gcc jrasmussen.c
/cygdrive/c/DOCUME~1/simon/LOCALS~1/Temp/cc0ReABU.o(.text+0x3a):jrasmussen.c: undefined reference to
`_OpenPrinterA@12'
collect2: ld returned 1 exit status

C:\docs\prog\c>gcc jrasmussen.c -l winspool

C:\docs\prog\c>ls -l /usr/lib/w32api/libwinspool.a
-rwxrwxrwx 1 simon Users 97896 Sep 12 23:37 /usr/lib/w32api/libwinspool.a

Perhaps you also have a w32api subdirectory that you must specifically
indicate in your -L option?

--
Simon.
Nov 14 '05 #7

P: n/a
Thank you very much for all your help !
I did not realize that windows programming was off-topic in this newgroup,
the title didn't suggest so, but maybe I should have looked into it... sorry
By the way, all my problems were solved by throwing away the space between
the -l and the winspool at the command prompt as suggested by Unur.

regards
Jimmy
Nov 14 '05 #8

P: n/a
Jimmy Rasmussen wrote:

(please dont top-post - corrected)
"Bruno Desthuilliers" <bd***********@removeme.free.fr> wrote in message
news:3f**********************@news.free.fr...
Jimmy Rasmussen wrote:
When trying to compile this program

-----------------------------------------
#include <windows.h>
Not standard

#include <winspool.h>


Not standard

main() {


must be
int main(int argc, char **argv)
or
int main(void)

LPHANDLE printer;


Not standard

OpenPrinter("sdsd",printer,NULL);


Not standard

}


main() must return an integer

-----------------------------------------

with gcc I get the following error message: undefined reference to
`OpenPrinterA@12'

What am I doing wrong? OpenPrinter is defined


no, it is not defined, it is *declared*.

in winspool.h so why is it not
found?


How do you expect your linker to resolve a symbol if you do not link
with the approriate object code (ie : object file or library) ? Read
your linker manual to know how to tell it to link to a specific lib, and
read your OS/API/Lib/Whatsoever doc to know which lib to link to.

Since winspool.h is found in the same directory as stdio.h etc., I assumed
that the code was part of the standard library of my compiler.
When we say 'standard', we mean *ISO* standard, the one that defines the
C language and its standard lib.
If this is
the case, is gcc not supposed to find the corresponding object files itself
?
Except for the standard lib, your linker is not supposed to link to
anything unless you tell him so.
The functions mentioned in the windows.h file (that you said was not
standard) can be used without mentioning any libraries to the linker.
The fact that *your* compiler behaves that way has nothing to do with
the C language.
I've
tried to explicitly tell gcc about the library (I found a file called
libwinspool.a) like this

gcc Printcharger.c -L "d:\Dev-C++\lib\" -l winspool

but with the same result. Maybe gcc (or my head) has not been properly
installed


Maybe you'd need to RTFM ? Anyway, compiler-specific problems are OT here.

Bruno

Nov 14 '05 #9

P: n/a
On Sat, 13 Dec 2003 18:16:55 +0100, in comp.lang.c , "Jimmy Rasmussen"
<ji****@get2net.dk> wrote:

Since winspool.h is found in the same directory as stdio.h etc., I assumed
that the code was part of the standard library of my compiler.
Not correct - the Standard Library is defined by ISO, but compiler
wrtiters are quite free to store otehr stuff in the same directory.
If this is the case,
its notis gcc not supposed to find the corresponding object files itself
but even if it were there's nothing that requires GCC or any other
compier to search for the objects. Not even MSVC does this- for
instance you have to tell it to link against the sockets lib.
? The functions mentioned in the windows.h file (that you said was not
standard) can be used without mentioning any libraries to the linker.
Windows.h also isn't standard, and if it can be used w/o being
specified, thats just how the compiler/linker was written.
gcc Printcharger.c -L "d:\Dev-C++\lib\" -l winspool


Thats probably the wrong command, or the right command in the wrong
order .Try asking in a gcc group.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 14 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.