PDA

View Full Version : DLL function(s) problem



silur
24th August 2012, 17:42
Simple question i have this code in an EXE:


void foo(int var1);
void foo(int var1,int var2);

so i can use both with the same name
how can i use this in a DLL my Qt compiler says that the 2 function confilts :confused:

amleto
24th August 2012, 18:35
there are plenty of other resources on the net available for building (c++) dlls. This is nothing to do with Qt programming.

silur
24th August 2012, 18:39
Qt is C++ , i didn't ask for trolling i asked for advice...

amleto
24th August 2012, 20:22
Qt is not c++. Qt is a library built with c++.

This is a Qt programming forum. You have not asked a Qt programming question.

Maybe here http://www.qtcentre.org/forums/9-General-Programming is what you are looking for.

silur
24th August 2012, 20:59
look go flame somewhere else i have a question i don't need a lecture what Qt u know I'M PROGRAMMING IN Qt do you think i don't know what it is?
you are a programmer in Qt, so rather than trollin' answer or flame another post

spirit
24th August 2012, 21:04
Well, you've posted in a wrong forum. That's it. If you're sure that's the correct place to ask then:
Did you fill HEADERS & LIBS variables for your pro-file? What's the complete error message?

amleto
24th August 2012, 22:05
look go flame somewhere else i have a question i don't need a lecture what Qt u know I'M PROGRAMMING IN Qt do you think i don't know what it is?
you are a programmer in Qt, so rather than trollin' answer or flame another post

Since you asked so nicely, and the fact that you seem unable to find your way into the correct forum, I will advise you to read my signature.

ChrisW67
25th August 2012, 08:48
Simple question i have this code in an EXE:


void foo(int var1);
void foo(int var1,int var2);

so i can use both with the same name
how can i use this in a DLL my Qt compiler says that the 2 function confilts :confused:

Firstly, there is no such beast as a Qt compiler. Your are using either a C++ or C compiler and this question has nothing to do with Qt.

Now, to address the C++ question. By way of example, this code:


#include <stdio.h>

void foo(int a) { printf("A = %d\n", a); }

void foo(int a, int b) { printf("A = %d B = %d\n", a, b); }

int main(int argc, char **argv) {
foo(1);
foo(2,3);
return 0;
}


Is perfectly valid C++, which allows overloaded functions, and compiles just fine with a C++ compiler. Despite deliberately using only C IO functions this code will not compile with a C compiler (GCC in my case), generating:


gcc -o test main.c
main.c:7:6: error: conflicting types for ‘foo’
main.c:3:6: note: previous definition of ‘foo’ was here
main.c: In function ‘main’:
main.c:15:5: error: too few arguments to function ‘foo’
main.c:7:6: note: declared here

You are most likely using C++ compiler, but this is still related.


Even with a C++ compiler, if you have forward declarations in the include file for your library like this:


#ifdef __cplusplus
extern "C" {
#endif

void foo(int var1);
void foo(int var1,int var2);

#ifdef __cplusplus
}
#endif

then you are telling the C++ compiler these are C-style declarations and it will not allow the overloaded names (just like a C compiler):


g++ -o test test.cpp main.cpp
In file included from main.cpp:1:0:
test.h:6:27: error: declaration of C function ‘void foo(int, int)’ conflicts with
test.h:5:6: error: previous declaration ‘void foo(int)’ here
main.cpp: In function ‘int main(int, char**)’:
main.cpp:6:10: error: too few arguments to function ‘void foo(int, int)’
test.h:6:6: note: declared here


Exactly what you are doing we cannot tell, but this information should give you a clue.