Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1056830 Posts in 42928 Topics- by 34874 Members - Latest Member: felipemaciel

October 24, 2014, 04:00:49 AM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)2 different C headers that have the same function name
Pages: [1]
Print
Author Topic: 2 different C headers that have the same function name  (Read 305 times)
InfiniteStateMachine
Level 10
*****



View Profile WWW Email
« on: February 26, 2013, 05:56:02 PM »

So I'm currently using 2 different libraries that both have a function called "connect" one is a library that brings in the windows.h header and the other is qt.

Unfortunately when I try to use the connect function in Qt I get a compile error that essentially says it has the wrong number of arguments because it expects the arguments for the windows command.

Now in C++ this would be resolved with namespaces. Is there any way to resolve this issue? I've tried using the global namespace operator (aka ::connect) but that did not resolve the situation.
Logged

eigenbom
Level 10
*****



View Profile WWW
« Reply #1 on: February 26, 2013, 06:14:30 PM »

i think i recall that Qt has a flag that forces it to use a more verbose form of connect(), like QT_SIGNAL_CONNECT(...) or something
Logged

Evan Balster
Level 10
*****


I live in this head.


View Profile WWW Email
« Reply #2 on: February 26, 2013, 06:16:32 PM »

This sort of thing can be hugely problematic -- I've had to deal with link errors in situations like this and it's generally very nasty.  C API developers need to remember to prefix and C++ API developers need to remember to use namespaces.

You might use more specific headers than windows.h -- it's sort of infamous for being a major source of namespace pollution.  Its min() and max() macros are particularly bad.
Logged

Creativity births expression.  Curiosity births exploration.
Our work is as soil to these seeds; our art is what grows from them...


Wreath, SoundSelf, Infinite Blank, Cave Story+, <plaid/audio>
InfiniteStateMachine
Level 10
*****



View Profile WWW Email
« Reply #3 on: February 26, 2013, 06:50:21 PM »

unfortunately it's not me who calls in the windows.h file. It's the commercial library the company I work for uses unfortunately.

Thanks for the tip eigen, I'll look into that.
Logged

eigenbom
Level 10
*****



View Profile WWW
« Reply #4 on: February 26, 2013, 07:19:50 PM »

np good luck Smiley
Logged

ThemsAllTook
Moderator
Level 10
******


Alex Diener


View Profile WWW
« Reply #5 on: February 26, 2013, 07:34:14 PM »

If nothing else works, you can potentially wrap one of your #includes in #define connect(...) some_other_name(...) ... #undef connect to rename one of the connects. I'm not entirely sure you won't run into problems at link time, though...
Logged
InfiniteStateMachine
Level 10
*****



View Profile WWW Email
« Reply #6 on: February 27, 2013, 10:24:19 PM »

Finally figured it out. Apparently connect is defined globally as a c function but also as a static function of QObject.

Heh many of my google searches for this problem resulted in this thread :D
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic