473,386 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

undefined reference to `OpenPrinterA@12'

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

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
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
"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
"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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: RU | last post by:
Hi, I am working on a porting project to port C/C++ application from unixware C++, AT&T Standard components to g++ with STL on Linux. This application has been working properly on...
1
by: Codemutant | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** I just cannot find what is undefined in this code.
1
by: Dom | last post by:
I'm new to c++. Just started learning it 24 hours ago. Am running into a compile problem. Please, no one waste the effort telling me to google it. I've been researching it for quite a while with no...
1
by: Andre Janssen | last post by:
Hi.... I tried to compile the following src with this command: "g++ -Wall -o bla alsaswitch.cpp". The src is an example src of xosd package. #include <xosd.h> int main (int argc, char...
3
by: Michael Sgier | last post by:
Hi i get thousands of messages like below. How shall i resolve that? Thanks Mcihael Release/src/Utility/RawImage.o: In function `CMaskImage::CMaskImage(int, int, char const*)':...
5
by: druberego | last post by:
I read google and tried to find the solution myself. YES I do know that you can get undefined references if you: a) forget to implement the code for a prototype/header file item, or b) you forget...
3
by: prakash.mirji | last post by:
Hello, I am getting below mention linker error when I tried to link my class test.C I use below command to compile test.C /usr/bin/g++ -g -fpic -fvisibility=default -D_POSIX_SOURCE...
1
by: taiyang902 | last post by:
i program under linux ,and using kdevelop c/c++. the code follow, #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <iostream> #include <cstdlib> using namespace std;
2
by: zqiang320 | last post by:
Hello: I execute make ,then get error: $ make Making all in libsbml/src make: Entering directory `/home/internet/mydoc/test_pj/libsbml/src' ........ /bin/sh ./libtool --tag=CC --mode=link...
3
by: tvnaidu | last post by:
I compiled tinyxml files (.cpp files) and when I am linking to create final exe in Linux, I am getting lot of errors saying "undefiend reference" to "operator new" and "delete", any idea?. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.