Hi ,
I am using fedora core 3 for development.For one of the project we got the source code library(SCL) of protocol which was written in "C".I am able to compile the SCL using gcc .But when I try to compile sample application which I have written in CPP with SCL, it gives loads of error(like undefined ref.)during liking.Please tell me approach to fix such kind of errors.


I cannot say exactly what you need to do as you give no details as to what sort of symbols are undefined (do they look like they could be C++ library symbols, or symbols from some other library or maybe something you have forgotten to implement or compile?).

These sorts of errors usually occur because you have not linked with all the required libraries and object files or, with some linkers you have not linked the libraries in the correct order (in some cases you may have to repeat some libraries or object files one or more times on the command line).

So first off: have you compiled all the source files and either used the resultant object files to link with or used them to create libraries which you then link with (or for shared libraries both, as you link the object files to create a shared library)?

Are all declared and called functions (and any global data) that have external linkage (i.e. are not specified in global scope as static) actually defined somewhere in the source code? That is have you remembered to write all the functions you are using and defined all global data objects?

Depending on how the SCL was built it may itself require additional libraries when linked with - which ones may also depend on what facilities of the SCL you are using. Check any documentation, and if that is not useful look for what header files are included in the source code - are they other than standard C library headers? These can give hints as to additional required libraries. Note for example that you may have to link against the maths library libm.a explicitly (-lm) (or similar) if it is required.

The sample application may require linking against libraries other than the SCL, C, C++ and other usual libraries.

Finally, did you build the C++ code using the g++ or gcc commands? The former is the GNU C++ compiler driver and the latter the GNU C compiler driver. There is not very much difference between the two, however one area where a difference presents itself is with the libraries automatically linked against: specifically gcc does _not_ automatically link against the C++ library. See the GCC documentation for details, e.g. the section on compiling C++ code at:


states quite clearly that gcc does _not_ add the C++ library (to the options passed to the linker presumably!), whereas g++ does, together with using other useful options for building from C++ source code.

Oh and just so you are aware of it: CPP (or cpp) is ambiguous. It can also mean the C Pre Processor, which is sometimes (usually on UN*X like systems) a separate program called cpp. You might try:

   man cpp

or check out the GNU pages on the GNU C Preprocessor:


and the overview at:


I could put forward the view that because the C preprocessor pre-dates C++ CPP or cpp would primarily mean the C preprocessor rather than C++. On the other hand I know that some sites - including AllExperts - sometimes have problems parsing text containing plus symbols ( + ). I have logged numerous bugs on this very point with AllExperts in the past, so the use here to mean C++ is understandable.

Hope this gives you some pointers and helps you move forward.  


All Answers

Answers by Expert:

Ask Experts


Ralph McArdell


I am a software developer with more than 15 years C++ experience and over 25 years experience developing a wide variety of applications for Windows NT/2000/XP, UNIX, Linux and other platforms. I can help with basic to advanced C++, C (although I do not write just-C much if at all these days so maybe ask in the C section about purely C matters), software development and many platform specific and system development problems.


My career started in the mid 1980s working as a batch process operator for the now defunct Inner London Education Authority, working on Prime mini computers. I then moved into the role of Programmer / Analyst, also on the Primes, then into technical support and finally into the micro computing section, using a variety of 16 and 8 bit machines. Following the demise of the ILEA I worked for a small company, now gone, called Hodos. I worked on a part task train simulator using C and the Intel DVI (Digital Video Interactive) - the hardware based predecessor to Indeo. Other projects included a CGI based train simulator (different goals to the first), and various other projects in C and Visual Basic (er, version 1 that is). When Hodos went into receivership I went freelance and finally managed to start working in C++. I initially had contracts working on train simulators (surprise) and multimedia - I worked on many of the Dorling Kindersley CD-ROM titles and wrote the screensaver games for the Wallace and Gromit Cracking Animator CD. My more recent contracts have been more traditionally IT based, working predominately in C++ on MS Windows NT, 2000. XP, Linux and UN*X. These projects have had wide ranging additional skill sets including system analysis and design, databases and SQL in various guises, C#, client server and remoting, cross porting applications between platforms and various client development processes. I have an interest in the development of the C++ core language and libraries and try to keep up with at least some of the papers on the ISO C++ Standard Committee site at http://www.open-std.org/jtc1/sc22/wg21/.


©2017 About.com. All rights reserved.