LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-13-2010, 09:26 AM   #1
Gracy
LQ Newbie
 
Registered: Nov 2005
Posts: 4

Rep: Reputation: 0
C++ linkage


I am porting a code which ran on HP unix to CentOS. It was a working code and compiled with gcc3.1.x and a c++ file and now I tried to compile with gcc3-3.4.6 and gcc4-4.2.4 also. But still I get this conflicts in declaration error as pasted below.

In file included from ../../../lol/ntk/nt_kslog.h:155,
from ../../../lol/ntk/nt_kernel.h:243,
from ../../../lol/ntk/nt_cp.h:110,
from ../../../soml/include/soml-afi-afu.h:131,
from ../../include/pcdb.h:58,
from ../../include/pcdb_addtypes.h:59,
from pcdb_addtypes.cc:94:

/opt/bcs/include/syslog.h:93: error: previous declaration of 'void syslog(int, const char*, ...)' with 'C++' linkage
/opt/bcs/include/syslog.h:93: error: conflicts with new declaration with 'C' linkage

I have the extern "C" included like this . But still I face the same problem . What Am I missing ??

#ifdef __cplusplus
extern "C" {
#endif

#include <syslog.h>
#include <stdarg.h>

#ifdef __cplusplus
}
#endif

Also , I work on Centos 5 box and it compiled without any issues on one machine and the same throws this error on other box with centos and both compilers.

Could anyone please help me , Where Am I going wrong ?
 
Old 01-13-2010, 09:48 AM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Unfortunately, nothing in the error text you posted shows the point at which the earlier C++ declaration is included. It only shows the nested includes that reach the C declaration.

If I understand correctly, the C declaration is the one you want and the C++ declaration is the one you don't want.

I assume the code you posted (that includes syslog.h wrapped within extern "C") is in some other header file or is somewhere other than the beginning of the .cpp file in which you get the error.

If you put that code first (either first directly within the .cpp or first withing the .h or .hpp that is included first by the .cpp) things should change. Depending on include guards in the path to the problem, it is possible that the problem would go away by making that code first. More likely, the error messages would reverse and give you details of the C++ declaration rather than the C declaration. Then you could properly diagnose the problem.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ linkage errors Gracy Linux - Software 1 01-13-2010 09:41 AM
[SOLVED] Library linkage using ld 1rDirEctoALgran0 Programming 8 08-20-2009 04:33 PM
Regarding the linkage of timer library eshwar_ind Programming 4 11-14-2005 03:17 AM
How does C libraries linkage work? Nerox Programming 4 12-25-2004 10:36 PM
GTK+2.5.0 and Pango 1.4.1 linkage problems.... SyBEX Linux - Software 10 10-29-2004 01:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration