Is there a difference between gcc and g++ for COPRTHR?

Moderator: dar

Is there a difference between gcc and g++ for COPRTHR?

Postby nickoppen » Wed Apr 27, 2016 11:41 am

Hi,

I wrote the host example for my last blog post in C and everything worked as expected (eventually).

Now I want to write my host program in C++ and use all the benefits of that language.

I'm getting some unexpected errors when calling the COPRTHR functions coprthr_getsym:

Code: Select all
   coprthr_kernel_t thr_mpiPassUni = coprthr_getsym(prg,"k_mpiPassUni");


When I compile this with g++ I get the error:

error: invalid conversion from ‘void*’ to ‘coprthr_kernel_t {aka coprthr_kernel*}’ [-fpermissive]

The same thing happens to coprthr_sym_t and coprthr_mem_t.

Am I missing something?

nick
Sharing is what makes the internet Great!
User avatar
nickoppen
 
Posts: 266
Joined: Mon Dec 17, 2012 3:21 am
Location: Sydney NSW, Australia

Re: Is there a difference between gcc and g++ for COPRTHR?

Postby sebraa » Wed Apr 27, 2016 12:48 pm

The difference between gcc and g++ is that they compile different languages.
While C++ is mostly compatible with C, there are some minor differences; not every C program is valid C++.

In your example, you see such a difference: In C++, you require an explicit cast there, e.g.:
Code: Select all
   coprthr_kernel_t thr_mpiPassUni = (coprthr_kernel_t)coprthr_getsym(prg,"k_mpiPassUni");
sebraa
 
Posts: 495
Joined: Mon Jul 21, 2014 7:54 pm

Re: Is there a difference between gcc and g++ for COPRTHR?

Postby nickoppen » Wed Apr 27, 2016 11:37 pm

Thanks sebraa, it's been a long time since I wrote any C and I was never any good at it.

My source code compiles now but I get a linker error. It can't find any of the coprthr libraries. I've got /usr/local/browndeer/lib in the linker search path where all of those libraries live. I seem to recall (from a past life) that there was a thing called extern "C" or something similar. Do I have to do something different for the linker?

Sorry about these dumb questions. It's been 15 years since I wrote code professionally. I'm in the mining industry and the most technical thing I do is Excel spreadsheets.

nick
Sharing is what makes the internet Great!
User avatar
nickoppen
 
Posts: 266
Joined: Mon Dec 17, 2012 3:21 am
Location: Sydney NSW, Australia

Re: Is there a difference between gcc and g++ for COPRTHR?

Postby sebraa » Thu Apr 28, 2016 12:31 pm

I have not used coprthr at all, so I can only look at error messages and if the problem is not related to coprthr, I can try to help. I need the precise message, though.

Another main difference between C and C++ is name mangling. Since in C++, you are allowed to have multiple functions with the same name (but differing arguments), the compiler changes the names internally to make them unique. If you then try to link C++ code to a C library (where the names are exactly as specified in the source code), the linker will not find the correct symbol names. This is what the "extern C" fixes.

You can try to include the coprthr header files inside an extern C block like this:
Code: Select all
extern "C" {
    #include <coprthr.h>
}


This should allow the linker to use the correct symbol names. But if the linker is actually not finding the library, then this won't help.
sebraa
 
Posts: 495
Joined: Mon Jul 21, 2014 7:54 pm

Re: Is there a difference between gcc and g++ for COPRTHR?

Postby nickoppen » Fri Apr 29, 2016 2:17 am

All good. As soon as I read "name mangling" it all came flooding back. It is looking for a C++ style name in the library but reporting an error using the "human readable" name used in the code.

Thank you for you help.

nick
Sharing is what makes the internet Great!
User avatar
nickoppen
 
Posts: 266
Joined: Mon Dec 17, 2012 3:21 am
Location: Sydney NSW, Australia

Re: Is there a difference between gcc and g++ for COPRTHR?

Postby sebraa » Fri Apr 29, 2016 12:30 pm

You're welcome. ;-)
sebraa
 
Posts: 495
Joined: Mon Jul 21, 2014 7:54 pm


Return to OpenCL

Who is online

Users browsing this forum: No registered users and 1 guest