Hi,
as far as I know I can link all C libraries in C++ as well. but I can't get it done with pslib. pslib is a library to create Postscript documents.
The exactly same code compiles and links with C and it doesn't when I
use C++.
This is my linking command:
gcc -o test -L/usr/lib/ -lps -lstdc++ test.cpp
and in /usr/lib is definitely the file
/usr/lib/libps.so -> libps.so.0.2.4
it all works fine when I compile my file as test.c as C
code. but with test.cpp I get these errors:
/tmp/ccSuItDe.o(.tex t+0x11): In function `main':
: undefined reference to `PS_boot()'
/tmp/ccSuItDe.o(.tex t+0x16): In function `main':
: undefined reference to `PS_new()'
[bla bla bla and so on............. .........]
collect2: ld returned 1 exit status
this is the stupid little piece of code I wrote after the
bigger project didn't compile:
#include <libps/pslib.h>
main(int argc, char *argv[]) {
PSDoc* sheet;
PS_boot();
sheet = PS_new();
PS_open_file(sh eet,"test.ps");
PS_set_info(she et,"Title","Hel loWorld");
PS_begin_page(s heet,841.9,595. 3);
PS_end_page(she et);
PS_shutdown();
};
what do I do wrong. BTW, I have debian [sid] running.
desperately asking
Thomas Ruschival 3 2488
Thomas Ruschival wrote: Hi, as far as I know I can link all C libraries in C++ as well. but I can't get it done with pslib. pslib is a library to create Postscript documents. The exactly same code compiles and links with C and it doesn't when I use C++. This is my linking command: gcc -o test -L/usr/lib/ -lps -lstdc++ test.cpp
Don't use gcc for linking anything that contains C++ code. Use g++. There is
more difference than -lstdc++.
and in /usr/lib is definitely the file /usr/lib/libps.so -> libps.so.0.2.4
it all works fine when I compile my file as test.c as C code. but with test.cpp I get these errors:
/tmp/ccSuItDe.o(.tex t+0x11): In function `main': : undefined reference to `PS_boot()' /tmp/ccSuItDe.o(.tex t+0x16): In function `main': : undefined reference to `PS_new()' [bla bla bla and so on............. .........] collect2: ld returned 1 exit status
this is the stupid little piece of code I wrote after the bigger project didn't compile:
#include <libps/pslib.h>
Maybe the pslib header is is not written in a C++-aware way. C++ uses name
mangling, which means that e.g. parameter types are added to the function
name to form an internal symbol for your function. C usually (and in the
case of gcc definitely) doesn't do that, so the functions cannot be found
by the linker if C linkage isn't explicitly requested. Most C headers have
someting like:
#ifdef __cplusplus
extern "C"
{
#endif
// header code
#ifdef __cplusplus
}
#endif
so that if it's compiled with a C++ compiler, C linkage is requested for the
functions declared in that header. If your header doesn't do that, you
could try surrounding the extern "C" around your #include, like:
extern "C"
{
#include <libs/pslib.h>
}
main(int argc, char *argv[]) { PSDoc* sheet; PS_boot(); sheet = PS_new(); PS_open_file(sh eet,"test.ps"); PS_set_info(she et,"Title","Hel loWorld"); PS_begin_page(s heet,841.9,595. 3); PS_end_page(she et); PS_shutdown(); };
what do I do wrong. BTW, I have debian [sid] running.
"Thomas Ruschival" <t.*********@vi vid-md.de> wrote... as far as I know I can link all C libraries in C++ as well. but I can't get it done with pslib. pslib is a library to create Postscript documents. The exactly same code compiles and links with C and it doesn't when I use C++.
The two languages are different enough to make it generally possible.
This is my linking command: gcc -o test -L/usr/lib/ -lps -lstdc++ test.cpp
and in /usr/lib is definitely the file /usr/lib/libps.so -> libps.so.0.2.4
it all works fine when I compile my file as test.c as C code. but with test.cpp I get these errors:
/tmp/ccSuItDe.o(.tex t+0x11): In function `main': : undefined reference to `PS_boot()' /tmp/ccSuItDe.o(.tex t+0x16): In function `main': : undefined reference to `PS_new()' [bla bla bla and so on............. .........] collect2: ld returned 1 exit status
this is the stupid little piece of code I wrote after the bigger project didn't compile:
#include <libps/pslib.h> main(int argc, char *argv[]) { PSDoc* sheet; PS_boot(); sheet = PS_new(); PS_open_file(sh eet,"test.ps"); PS_set_info(she et,"Title","Hel loWorld"); PS_begin_page(s heet,841.9,595. 3); PS_end_page(she et); PS_shutdown(); };
what do I do wrong. BTW, I have debian [sid] running.
First of all, the code is not valid C++ code. The 'main' has implicit
return type, which is not allowed in C++.
Second, since the contents of <libps/pslib.h> are not known, the use of
it within a C++ program is not necessarily guaranteed.
Third, you have a superfluous semicolon after the closing curly brace.
I strongly recommend asking in comp.os.linux.d evelopment.app, since the
compiler command-lines, and paths, and how 'ld' resolves symbols, is all
platform-specific.
V
Thanks alot,
extern "C"{
#include <>
}
did the trick! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Wolfgang |
last post by:
I have a problem with linking my CPP Code under a irix6 machine (sgi,
UNIX). In my CPP code I use some Functions which are written in
Python. So its a kind of CPP wrapper for my Python functions In my
Python Code I use threads to communicate over the network and stuff
like this. Compilation and linking are working very well under Windows
and Linux with the same code. Under the sgi, UNIX machine some errors
occur and I don't no why....
|
by: Steven T. Hatton |
last post by:
Is there anything that gives a good description of how source code is
converted into a translation unit, then object code, and then linked. I'm
particularly interested in understanding why putting normal functions in
header files results in multiple definition errors even when include guards
are used.
--
STH
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla:...
|
by: Steven T. Hatton |
last post by:
I just read this in the description of how C++ is supposed to be
implemented:
"All external object and function references are resolved. Library
components are linked to satisfy external references to functions and
objects not defined in the current translation. All such translator output
is collected into a program image which contains information needed for
execution in its execution environment."
What I'm wondering is what exactly...
|
by: gasturbtec |
last post by:
please help im new at access programming and i just got this project
dropped in my lap because the old programmer quit. i've been doing ok
so far but now i need to add code to an existing database that is used
to connect to other databases and generate reports. below is sample
code of how the database does the linking i hope i give you enough
info to help me but if not let me know and i will give more.
Sub txtShipDataFileSub()
Dim...
|
by: Rudy Ray Moore |
last post by:
I work with a multi-project workspace. One project (the "startup" project)
has a "Configuration Type" of "Application (.exe)". The other 40 projects
have a "Configuration Type" of "Static Library (.lib)".
My question:
Should the linker incrementally link when I make a change to one of the
..cpps in one of my .lib projects?
For VC6 the answer is yes.
| |
by: Rudy Ray Moore |
last post by:
I've been having trouble getting incremental linking to work under Visual
C++ .net 2003 7.1 for my multi-project workspace. Ronald Laeremans and Carl
Daniel (and a few others) helped me figure it out.
Short answer: I should never have expected incremental linking to work.
Short answer addendum: Linking is slower in 7.1/.net/2003 than VC++6.
===
|
by: Philip Lowman |
last post by:
I am in the process of trying to migrate a couple of build solutions to
Visual Studio Express 2005 from VS 2003 Professional and I am running
into a weird C/C++ runtime library linking issue when using the /MT
compilation option. Our debug solution's /MTd flag works fine and
using /MD also seems to work ok. For some reason I can't fathom, when
I use /MT, linking the static excutable completely dies (problems
resolving symbols in the STL,...
|
by: srikar |
last post by:
what is the difference between static linking & dynamic linking,
what are the advantages of each?
How to perform static linking & Dynamic linking
by using gcc -o liniking will be done , but how can we control the type of linking
Hi any one please help me to clarify my doubt
|
by: nipun sabharwal |
last post by:
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc\\bgi");
setcolor(GREEN);
settextstyle(4,0,8);
outtextxy(200,50,"TIME");
setcolor(YELLOW);
settextstyle(4,0,8);
outtextxy(100,190,"SCHEDULER");
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |