f



C++/C-library linking (pslib)

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(.text+0x11): In function `main': 
 : undefined reference to `PS_boot()' 
 /tmp/ccSuItDe.o(.text+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(sheet,"test.ps"); 
 PS_set_info(sheet,"Title","HelloWorld"); 
 PS_begin_page(sheet,841.9,595.3); 
 PS_end_page(sheet); 
 PS_shutdown(); 
 }; 
 
 what do I do wrong. BTW, I have debian [sid] running. 
 
 desperately asking 
 Thomas Ruschival 
0
11/13/2004 6:55:33 PM
comp.lang.c++ 49423 articles. 7 followers. Post Follow

3 Replies
554 Views

Similar Articles

[PageSpeed] 6

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(.text+0x11): In function `main':
>  : undefined reference to `PS_boot()'
>  /tmp/ccSuItDe.o(.text+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(sheet,"test.ps");
>  PS_set_info(sheet,"Title","HelloWorld");
>  PS_begin_page(sheet,841.9,595.3);
>  PS_end_page(sheet);
>  PS_shutdown();
>  };
>  
>  what do I do wrong. BTW, I have debian [sid] running.

0
ramagnus (3487)
11/13/2004 7:15:17 PM
"Thomas Ruschival" <t.ruschival@vivid-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(.text+0x11): In function `main':
> : undefined reference to `PS_boot()'
> /tmp/ccSuItDe.o(.text+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(sheet,"test.ps");
> PS_set_info(sheet,"Title","HelloWorld");
> PS_begin_page(sheet,841.9,595.3);
> PS_end_page(sheet);
> 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.development.app, since the
compiler command-lines, and paths, and how 'ld' resolves symbols, is all
platform-specific.

V 


0
v.Abazarov (13256)
11/13/2004 7:18:58 PM
Thanks alot,
extern "C"{
	#include <>
}

did the trick!

0
11/14/2004 12:57:34 PM
Reply:

Similar Artilces:

jython and C-c C-c
How do I get C-c C-c to work with jython? I have the jpython command set to jython, and I can start the interpreter with C-C ! and then use C-c C-c, but this is rather frustrating. If I try to use C-c C-c without first starting the interpreter in another window I get wrong type argument: sequencep, jpython Thanks, Dave Cook ...

Better C/C++ Than C/C++?
I am looking for a good systems programming language that can be used instead of C/C++. My qualifications for the language are: * mature compiler(s) that produce native-code binaries (for Windows) * open source - preferable, but not 100% necessary Thanks, Kevin "Kevin Albrecht" <kevin@albrecht.net> writes: > I am looking for a good systems programming language > that can be used instead of C/C++. My qualifications > for the language are: > > * mature compiler(s) that produce native-code > binaries (for Windows) Ocaml, D, cyclone, Eiffel, Beta > * open source - preferable, but not 100% necessary what's wrong with using C? Friedrich > what's wrong with using C? Too low level, no built-in garbage collection. -- Kevin "Kevin Albrecht" <kevin@albrecht.net> writes: >> what's wrong with using C? > > Too low level, Well the Smalltalk people say, have a small language and a big library. I assume C's library status beyond that of Smalltalk. > no built-in garbage collection. Use the Boehm Weisser GC. Friedrich "Kevin Albrecht" <kevin@albrecht.net> wrote in message news:<2TiYb.237892$rj7.1641209@twister.tampabay.rr.com>... > I am looking for a good systems programming language > that can be used instead of C/C++. My qualifications > for the language are: > > * mature compiler(s) that produce native-code > binaries (for Windows) > ...

slime C-c C-c annoyance
Does anyone have a good workaround for this problem other than: just be careful! When I've compiled a large package and slime has given me a *slime-compilation* buffer, I like to work through this buffer issue by issue, fixing the errors, warnings, etc. But If I ever press C-c C-c in the editor window while fixing an error, slime destroys the *(slime-compilation* buffer with the compilation output of C-c C-c. Jim Newton <jimka.issy@gmail.com> writes: > Does anyone have a good workaround for this problem other than: just be careful! > > When I've compiled a ...

C/C++ in matlab and matlab in C/C++ ?
Is it possible to read C/C++ code in matlab and the other way around too? Hi, as long as C or C++ are written in text files you can edit them in the matlab editor. To see the special character of C or C++ coding language, in the editor go to menus: file>preferences>Edito/Debugger>language and on popup "Language" select "C/C++". This does not allow you to run the C/C++ code, just to view it i nicer way... regards, chris saneman <asdfsdf@asd.com> wrote in message <frl846 $f8i$2@news.net.uni-c.dk>... > Is it possible to read C/C...

C/C++ in MATALB or MATLAB in C/C++?
Hi I've been asking on the net how to use MEX properly so that I can use C/C++ in MATLAB, but information is not forthcoming. There seems to be a lot on using MATLAB in C/C++ but not the other way around. I understand Mathworks is trying very hard to sell the Matlab Compiler, but even so, why is it SO hard to get information about MEX? Or is it that I've missed something very fundamental, meaning that I'm struggling over something that is actually quite easy? Any thoughts and info would be great. Thanks BullDog BullDog wrote: > Hi > > I've been asking on the net ...

C as a Subset of C++ (or C++ as a superset of C)
Isn't it a lame use of human time and effort to maintain completely separate C and C++ standards? As in the words of Betty White about Facebook: "It seems like an incredible waste of time". Why don't the two standards groups get together and agree on a common specification for the ground which both standards cover? There would still be two separate standards, but they'd both be exactly the same for the common ground. The common ground document could be referred to by both standards instead of being maintained by both groups in individual efforts resulting in...

c------->c++ and c++------>c
We can write c program in turbo c++ editor.But reverse is not true why? i.e The program will not compile if u write c++ program in turbo c editor vim wrote: > We can write c program in turbo c++ editor.But reverse is not true why? > i.e The program will not compile if u write c++ program in turbo c > editor This isn't about C; this is about some editor. Why the fircone should /we/ know? Ask in a relevant group. [And /why/, in an editor specialised to some specific programming languages, would you expect it to compile a /different/ one? Would you expect turbo perl to compi...

C++ code with C-style interface for a library to be used in C++ and C?
Hi! I have a question about building and then using libraries containing C++ code. Let's say I have some C++ code and a .cpp file with 1 function that uses some other C++ code / classes etc... Also, any possible exception is handled within the function itself. In code: MyModule.h ---------- #ifndef MYMODULE_H #define MYMODULE_H extern int Test(float inParam1,float inParam2,float* outResult); #endif // #ifndef MYMODULE_H MyModule.cpp ------------ #include "MyModule.h" #include "MyClasses.h" // contains MyClassA and MyClassB int Test(float inParam1,float inParam2,...

C, C++ and C# Forums
Throne Software has opened up C, C++ and C# Forums at: http://www.thronesoftware.com/forum/ Join us! Throne Software wrote: > Throne Software has opened up C, C++ and C# Forums at: > > http://www.thronesoftware.com/forum/ For all of your forums newsgroups already exist. > Join us! Why? Don't see any reason to support your marketing. ...

C,, C++, Java, C#
I come from C,C++,Java and C#. What can SmallTalk do for me and for what cost? Regarding the Squeak thing, it's interesting though confusing. Is it an IDE? Why are the menus so wacky? "DM McGowan II" <nospam@nospam.net> wrote in message news:PLednX2vnLd11IncRVn-rA@comcast.com... > I come from C,C++,Java and C#. What can SmallTalk do for me ...? Ask not what Smalltalk can do for, but what can you do with Smalltalk. :-) In very few words, it significantly reduces time to market, while enhancig the development experience. This is because: 1. It manages the memory for you, so you don't have to allocate/deallocate all the time (the source of some of the most nasty bugs in C). Java and C# learnt that feature from ST. 2. It has single inheritance. 3. All the development is in a single file, called the image, so you don't have to fish for where did you put that missing class. Yet, you don't have to go through thousands of lines of code to find the method you wrote three months ago. 4. It's the language for which it's easier to work within the Agile methodologies. 5. It's strongly typed without being unnecessarily redundant. 6. It's "wacky" interface releases you from the need to use curlys. 7. It comes with a huge library, so you don't need to reinvent the wheel as much. 8. It's debugger is highly integrated and friendly, so the experience of findin...

C, C++ and C# Forums
Throne Software has opened up C, C++ and C# Forums at: http://www.thronesoftware.com/forum/ Join us! In article <1120963701.862698.160260@g14g2000cwa.googlegroups.com>, Throne Software <mail@thronesoftware.com> writes >Throne Software has opened up C, C++ and C# Forums at: > >http://www.thronesoftware.com/forum/ > >Join us! Why? The beauty of news groups is that they come to me I don't have to go to them. Also all the people who have been around a while know what they are doing and are here. I noticed that there are some C and C++ Forums on another system. Full of the blind (opinionated) leading the blind. The problem is that as the experienced people who have been around a long while are on usenet. the system works. Why move. Certainly not to a forum on a commercial web site. The web site might go down. Usenet can't. Web based systems are not as safe. I have to trust you about cookies and all sorts. (active X etc). Usenet is international and independent. It is not controlled by anyone. Why would anyone move from this system to a web based one in a a rogue state? There is no point in running a web based forum except as a support forum for your own products. -- \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ \/\/\/\/\ Chris Hills Staffs England /\/\/\/\/ /\/\/ chris@phaedsys.org www.phaedsys.org \/\/\ \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ Chris Hills wrote: > In article <1120963701.862...

c,c++,obj-c
Of the 3 languages titled in this post is c++ older than obj-c ? Would someone experienced in C be able to dive right into C++ rather than obj-c ? Java is out for me now except applet programming I think I'm going to go with just C and C++. Bill Bill Cunningham wrote: > Of the 3 languages titled in this post is c++ older than obj-c ? Why does that matter? Do you want to use an old language? Try Fortran or LISP. > Would > someone experienced in C be able to dive right into C++ rather than > obj-c ? Not quite dive in, at least not into the OO parts of C++. ...

C, C++ and C# Forums
Throne Software has opened up C, C++ and C# Forums at: http://www.thronesoftware.com/forum/ Join us! ...

Is this C or C++?
Simple question. If the task is (for example): "Write a C++ program which asks user his name (less than 20 chars) and prints it." Then, is this code a correct answer: char name[100]; cout<<"Your name?"<<endl; cin>>name; cout<<name<<endl; The point being, that the code uses C string "char name[]" and not C++ std::string. C is a subset of C++, so isnt it logically speaking a C++ program? On Tue, 19 Nov 2013 21:44:40 -0000, "crea" <no@com.notvalid> wrote: >Simple question. If the task is (...

About C and C++
Hello... I have saw some programmers talking about C on the C's forums... But as you have seen me talking before on my post titled "Software life cycle" , you have noticed that i have talked about the criterions that is "Maintainability" and "modifiability", what i don't like in C is that if you want to group efficiently functions and some propoerties that are shared inside an object , you can not do that efficiently as can do Object Pascal or C++, if you are writing in C you have to use global variables, but that's not good for "m...

About C and C++
Hello, I will resume it like this: On the criterias of "complexity" and "difficulty", the C and C++ programming languages are more complex and difficult than Object Pascal for example, so since they are more complex and difficult they are likely to create something like a darwinian filter who don't let the weaker humans among us humans to cross or to climb the social ladder, this is why i think that C and C++ do participate to social darwinism, this is why i say that C and C++ are bad. Thank you, Amine Moulay Ramdane. On Sun, 08 Jun 2014 06:1...

C and C++
Hello, I have been having trouble getting used to C. A very simple language. Could this be because I was very familiar with C++ before trying to learn C? The fstream header is so simple. using fopen, fread and fwrite for example seems complicated. Bill "Bill Cunningham" <nospam@nspam.com> writes: > I have been having trouble getting used to C. A very simple > language. Could this be because I was very familiar with C++ before trying > to learn C? The fstream header is so simple. using fopen, fread and fwrite > for example seems compli...

C to C++
Hi all In C I have previously created structures that contain themselves e.g. typdef struct Node_tag { struct Node_tag ptrNodes; float nodeNumber } Node; This worked fine, but trying to do the same in C++ doesn't work, any suggestions. Thanks daveR This day of Fri, 30 Apr 2004 10:39:02 +0100, "Charlotte Dean" <charlottedean@(NO5PAM)sheffield17a.fsnet.co.uk> proclaimed: >Hi all > >In C I have previously created structures that contain themselves e.g. > >typdef struct Node_tag { > ...

C and C
Please Who wants to post Command and Conquer Red Alert 3. I'm looking for the whole version. If you do so Thank you. --------------= Posted using GrabIt =---------------- ------= Binary Usenet downloading made easy =--------- -= Get GrabIt for free from http://www.shemes.com/ =- Shaniel's Usenet wrote: > Please > Who wants to post Command and Conquer Red Alert 3. > I'm looking for the whole version. > If you do so Thank you. > > > --------------= Posted using GrabIt =---------------- > ------= Binary Usenet downloading made easy =--------- &g...

More about C and C++
Hello, I have wrote: >I will resume it like this: >On the criterias of "complexity" and "difficulty", the C and C++ >programming languages are more complex and difficult than Object >Pascal for example, so since they are more complex and difficult they >are likely to create something like a darwinian filter who don't let >the weaker humans among us humans to cross or to climb the social >ladder, this is why i think that C and C++ do participate to social >darwinism, this is why i say that C and C++ are bad. Joseph ...

More about C and C++
Hello, I have wrote: >I will resume it like this: >On the criterias of "complexity" and "difficulty", the C and C++ >programming languages are more complex and difficult than Object >Pascal for example, so since they are more complex and difficult they >are likely to create something like a darwinian filter who don't let >the weaker humans among us humans to cross or to climb the social >ladder, this is why i think that C and C++ do participate to social >darwinism, this is why i say that C and C++ are bad. Josep...

c++ to c
Hello Everyone, I have a project where I need to write C++ code in C (due to OS issues). Can someone please show me exactly what I need to do to convert the code to C. Thanks Jami Here is the code I need to convert to C++: class CTestSuite : public CTestSuiteBase { public : CTestSuite(CTestBase *aTest); virtual ~CTestSuite(); virtual TInt InvokeTestL(int argc, char * argv[], TTestConfig * aConfig) ; IMPORT_C CTestSuite *GetTestSuite(); virtual int RunTestL(int aArgc, char *aArgv [], TTestConfig *aConfig); protected: CTestBase *iTest; } ; class CTestSuiteBase : p...

c++ or c#
hello all experiancesd techies, i am a final yr engg student with knowledge of c++ n java. i want to start windows programing, n hence have to decide whether to choose my language as c++ or c#. please guide me which language would benefit in the long run, if i intend to persue a job in a product development company/( like adobe) after graduation,(not in a consultancy like acenture). also suggest me good books for that. thanx a lot <pravin.chaudhary@gmail.com> wrote in message news:1131971088.291580.42500@g47g2000cwa.googlegroups.com... > i am a final yr engg student with ...

c++/c
hi i have been recently told that there is no exception handling ic c+ +.?? as far as i remember i have read, it has. also java has exception handling for sure but there we can use finally also which we cant use in c ++. what other differences do we have in the two languages c++ and java in exception handling. and which one is better? rupika wrote: > > i have been recently told that there is no exception handling ic > c++.?? You should ask about C in comp.lang.c, about C++ in comp.lang.c++. -- [mail]: Chuck F (cbfalconer at maineline dot net) [page]: <http://cbfalconer.home...

Web resources about - C++/C-library linking (pslib) - comp.lang.c++

FlyPic HD - GPS Slideshow for iPad on the iTunes App Store
Get FlyPic HD - GPS Slideshow on the App Store. See screenshots and ratings, and read customer reviews.

About Us - New Ideas On How To Design Better Software
Code Farms Inc is one of the oldest class-library companies in business. It was founded in 1988 with a mission to deliver simpler and more efficient ...

Glibc Flaw Affects Thousands Of Linux Apps But How Dangerous Is It?
The difficulty involved in exploiting flaw could mitigate some of the risk, say some security researchers.

openjpeg - Open-source C-Library for JPEG 2000 - Google Project Hosting
The OpenJPEG library is written in C language, released under the BSD license and targets Win32, Unix and Mac OS platforms. The library is developed ...

Potential intrusion into NetBSD systems via FTP server
Bug report claims code can be planted and executed with root rights when directories are created with rigged names.

ECE 5760
Skip to main content Cornell University SEARCH CORNELL: Pages People more options ECE ECE intranet CUinfo Cornell Library Bruce Land Advanced ...

libFirm - optimization and machine code generation
About Features Download Documentation Projects Development Contact Publications Firm is a C-library that provides a graph-based intermediate ...

C – Code Hunt
Awesome C, every day.

ClearSilver
Clearsilver is a fast, powerful, and language-neutral HTML template system. In both static content sites and dynamic HTML applications, it provides ...

SourceForge Open Source Mirror Directory / Mirror Projects / All
Error: CSS did not load. This may happen on the first request due to CSS mimetype issues. Try clearing your browser cache and refreshing. SourceForge ...

Resources last updated: 3/1/2016 10:50:13 PM