Functions not returning the correct value in DLL
This is so frustrating! I don't know why this is happening. I have a file named weirdDLL.c :
double five() {
return 5.0;
}
I have another file called weirdTest.c
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv) {
double f = five();
if (f != 5.0) {
printf("Test failed with %f", f);
return 1;
}
return 0;
}
I expect that when compiling and linking to the DLL, the code in the weirdTest will exit without errors. I am compiling 64 bit Windows 7 using gcc (cygwin) using the commands:
gcc -c weirdDLL.c
gcc -shared -o weirdDLL.dll weirdDLL.o
gcc -o test weirdtest.c -L./ -l weirdDLL
./test
Output:
Test failed with 0.000000
The DLL seems to link correctly because the compiler doesn't complain about the missing "five" feature. Also, when I add print statements to the DLL, they show up in order. What have I done wrong?
+3
source to share
2 answers