declaration of C functrion conflicts with ....

Topics for the Eclipse Environment
Post Reply
oleg_osov
Posts: 20
Joined: Tue Jan 04, 2011 1:58 pm
Location: Montreal, Canada
Contact:

declaration of C functrion conflicts with ....

Post by oleg_osov »

Hello,

I'm developing a pretty big project. The project itself builds flawlessly. But when I add my C++ code to the project, I get tons of errors in my code. Original code is built without problems. I'm pulling my hairs out for several hours and I can't find a solution.

I get many such errors:

Code: Select all

m68k-elf-g++ -O2 -falign-functions=4 -IC:\nburn\include -IC:\nburn\MOD5234\include -IC:\nburn\gcc-m68k\m68k-elf\include -IC:\nburn\MOD5234\include\etpu -IC:\nburn\MOD5234\include\etpu\functions_API -IC:\nburn\MOD5234\include\etpu\cpu -IC:\nburn\MOD5234\include\etpu\sets -IC:\nburn\NBEclipse\workspace\ISaGRAF_Multi\Etcp -IC:\nburn\NBEclipse\workspace\ISaGRAF_Multi\Hsd -IC:\nburn\NBEclipse\workspace\ISaGRAF_Multi\IsaCmg -IC:\nburn\NBEclipse\workspace\ISaGRAF_Multi\IsaIxd -IC:\nburn\NBEclipse\workspace\ISaGRAF_Multi\IsaIxl -IC:\nburn\NBEclipse\workspace\ISaGRAF_Multi\IsaKer -IC:\nburn\NBEclipse\workspace\ISaGRAF_Multi\IsaNwl -IC:\nburn\NBEclipse\workspace\ISaGRAF_Multi\IsaRsi -IC:\nburn\NBEclipse\workspace\ISaGRAF_Multi\IsaSrv -IC:\nburn\NBEclipse\workspace\ISaGRAF_Multi\IsaSys -IC:\nburn\NBEclipse\workspace\ISaGRAF_Multi\IsaVm -IC:\nburn\NBEclipse\workspace\ISaGRAF_Multi\IsaCiA\include -gdwarf-2 -Wall -Wno-write-strings -c -fmessage-length=0 -fno-rtti -fno-exceptions -mcpu=5208 -DMOD5234 -DMCF5234 -oIsaCiA\emcy.o ..\IsaCiA\emcy.cpp
In file included from C:\nburn\include/startnet.h:41,
                 from C:\nburn\NBEclipse\workspace\ISaGRAF_Multi\IsaSys/dsys0def.h:63,
                 from C:\nburn\NBEclipse\workspace\ISaGRAF_Multi\IsaCiA\include/applicfg.h:26,
                 from C:\nburn\NBEclipse\workspace\ISaGRAF_Multi\IsaCiA\include/can_data.h:35,
                 from ..\IsaCiA\emcy.cpp:35:
C:\nburn\include/ip.h: In function 'IPPKT* GetIpPkt(EFRAME*)':
C:\nburn\include/ip.h:240: error: declaration of C function 'IPPKT* GetIpPkt(EFRAME*)' conflicts with
C:\nburn\include/ip.h:235: error: previous declaration 'IPPKT* GetIpPkt(pool_buffer*)' here
C:\nburn\include/ip.h: In function 'UDPPKT* GetUdpPkt(pool_buffer*)':
C:\nburn\include/ip.h:262: error: declaration of C function 'UDPPKT* GetUdpPkt(pool_buffer*)' conflicts with
C:\nburn\include/ip.h:249: error: previous declaration 'UDPPKT* GetUdpPkt(IPPKT*)' here
C:\nburn\include/ip.h: In function 'UDPPKT* GetUdpPkt(pool_buffer*)':
C:\nburn\include/ip.h:264: error: cannot convert 'pool_buffer*' to 'EFRAME*' for argument '1' to 'IPPKT* GetIpPkt(EFRAME*)'
C:\nburn\include/ip.h: In function 'UDPPKT* GetUdpPkt(EFRAME*)':
C:\nburn\include/ip.h:266: error: declaration of C function 'UDPPKT* GetUdpPkt(EFRAME*)' conflicts with
C:\nburn\include/ip.h:262: error: previous declaration 'UDPPKT* GetUdpPkt(pool_buffer*)' here
C:\nburn\include/ip.h: In function 'UDPPKT* GetUdpPkt(pool_buffer*)':
C:\nburn\include/ip.h:268: error: cannot convert 'IPPKT*' to 'EFRAME*' for argument '1' to 'UDPPKT* GetUdpPkt(EFRAME*)'
C:\nburn\include/ip.h: In function 'UDPPKT* GetInitUdpPkt(pool_buffer*)':
C:\nburn\include/ip.h:280: error: declaration of C function 'UDPPKT* GetInitUdpPkt(pool_buffer*)' conflicts with
C:\nburn\include/ip.h:273: error: previous declaration 'UDPPKT* GetInitUdpPkt(IPPKT*)' here
C:\nburn\include/ip.h: In function 'UDPPKT* GetInitUdpPkt(pool_buffer*)':
C:\nburn\include/ip.h:282: error: cannot convert 'pool_buffer*' to 'EFRAME*' for argument '1' to 'IPPKT* GetIpPkt(EFRAME*)'
Build error occurred, build is stopped
Time consumed: 4357  ms.  
This code could be easily compiled on Linux, this is pure ANSI C code, but the file has .cpp extension.

Somebody could explain me, what's the heck? There are two GetIpPkt() functions in the ip.h, but on another code it doesn't lead to an error.

P.S. NNDK-MOD5234-KIT, NBEclipse 2.4 RC2, g++ 4.2.1
Best regards,
Oleg Osovitskiy
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: declaration of C functrion conflicts with ....

Post by rnixon »

Hi,

"This code could be easily compiled on Linux, this is pure ANSI C code, but the file has .cpp extension."

What does that mean? Are you running under linux or windows? How exactly does linux play into this?
User avatar
tod
Posts: 587
Joined: Sat Apr 26, 2008 8:27 am
Location: Southern California
Contact:

Re: declaration of C functrion conflicts with ....

Post by tod »

It was pretty hard to understand what you were asking but here's my assumption. You had a working library that is written in C and compiles under linux. You are now trying to use that library in the NetBurner and call it from C++ code you have written. If that is correct here are a few pointers (and I have no idea what your experience level is so don't be insulted)

1. You don't have to write in C++ (did I just say that?), you can write in C for the NetBurner and call your C code that way. The C++ compiler is much more robust and typesafe. That means it's way pickier about the type of parameters. A pointer to an EEFRAME is not a pointer to an EPACKET you may need a dynamic cast.
2. When using C++, name mangling goes on, become familiar with the extern C construct
3.Linux supports all kind of libraries in its API that uCOS is not going to have. You will have to rewrite those portions of the C code to work with the NetBurner.
4. The NB API tends to pollute the global namespace, ie they don't use namespaces. You probably want to wrap the code you're bringing in in a namespace. You are either bringing in another GetIpPkt or you are missing an include guard somewhere. (The latter is probably the more likely reason).

In general divide and conquer. Bring in smaller pieces at a time. Sometimes commenting out includes can help you find the missing include guard. I suspect all includes that are in .h files rather than in the .cpp file. Often you can just add what seems like a redundant ifndef around the include. Drill into the .h see what the include guard is then wrap your #include with a separate include guard. This had the advantage of speeding up the compile (at least in theory) since it now doesn't have to look inside the .h file to check the include guard. I have inherited code where just changing the order of the includes fixed these types of problems.
oleg_osov
Posts: 20
Joined: Tue Jan 04, 2011 1:58 pm
Location: Montreal, Canada
Contact:

Re: declaration of C functrion conflicts with ....

Post by oleg_osov »

Thank you for such a detailed explanation.

I know about name mangling and about difference between C and C++.
I have Linux as my primary host OS, I run VirtualBox, guest OS is WinXP. NBEclipse is running inside of the Virtual Machine.

I have a big working project for NB. Originally it was for 5272, I adapted it to 5234. I have linux library. It's pure ANSI C, but uses timers and threads. I replaced POSIX timers with NB timers, eliminated POSIX threads and changed extensions from .c to .cpp
I added my library to a separate directory. The entire project has no one .c file.

My big project has one global file with important definitions, its name dsys0def.h, it includes startnet.h.
As you can see from my error message, error is occurred while compiling emcy.cpp.

Argh, I found a bug!!! As it was ANSI C library, in ONE of its headers it had such a code:

Code: Select all

#ifdef __cplusplus
extern "C" {
#endif


It's my fault! When I removed all this extern "C", then I'm getting NO error, because name mangling is working now.

Thank you guys, very much!!!
Best regards,
Oleg Osovitskiy
Post Reply