I hope someone can help me with my problem. Some months ago I started to write a Python library in C++, which includes dynamic function calls (by using the DynCall library, which worked very well). Now, I tried to include dynamic function hooks (by using your-name_here's DynDetours library), but I'm getting "undefined reference to *" errors, when I try to compile it on Windows. Linux works fine. Here is a link to my SVN: https://www.assembla.com/code/binutils/subversion/nodes
Output:
Code: Select all
C:\Users\Robin\Programming\C++\binutils>python setup.py build -c mingw32
running build
running build_ext
building 'binutils_C' extension
creating build
creating build\temp.win32-2.5
creating build\temp.win32-2.5\Release
creating build\temp.win32-2.5\Release\src
C:\MinGW\bin\gcc.exe -mdll -O -Wall -Isrc/dyncall/include -Isrc/DynDetours/include -Isrc/ASMJit -Isrc/testlib -IC:\Python25\i
nclude -IC:\Python25\PC -c src/binutils_main.cpp -o build\temp.win32-2.5\Release\src\binutils_main.o -fvisibility=hidden -fvi
sibility-inlines-hidden
In file included from src/ASMJit/AsmJit/AsmJit.h:373:0,
from src/DynDetours/include/asmbridge_class.h:12,
from src/DynDetours/include/detour_class.h:18,
from src/binutils_main.cpp:30:
src/ASMJit/AsmJit/Build.h:130:15: Warnung: ?void AsmJit::crash(int*)? definiert, aber nicht verwendet [-Wunused-function]
C:\MinGW\bin\gcc.exe -mdll -O -Wall -Isrc/dyncall/include -Isrc/DynDetours/include -Isrc/ASMJit -Isrc/testlib -IC:\Python25\i
nclude -IC:\Python25\PC -c src/binutils_scanner.cpp -o build\temp.win32-2.5\Release\src\binutils_scanner.o -fvisibility=hidde
n -fvisibility-inlines-hidden
C:\MinGW\bin\gcc.exe -mdll -O -Wall -Isrc/dyncall/include -Isrc/DynDetours/include -Isrc/ASMJit -Isrc/testlib -IC:\Python25\i
nclude -IC:\Python25\PC -c src/binutils_hooks.cpp -o build\temp.win32-2.5\Release\src\binutils_hooks.o -fvisibility=hidden -f
visibility-inlines-hidden
src/binutils_hooks.cpp: In Elementfunktion ?virtual HookRetBuf_t* CCallbackManager: :D oPreCalls(CDetour*)?:
src/binutils_hooks.cpp:79:67: Warnung: veraltete Konvertierung von Zeichenkettenkonstante in ?char*? [-Wwrite-strings]
In file included from src/ASMJit/AsmJit/AsmJit.h:373:0,
from src/DynDetours/include/conv_interface.h:14,
from src/binutils_hooks.cpp:27:
src/ASMJit/AsmJit/Build.h: Im globalen G?ltigkeitsbereich:
src/ASMJit/AsmJit/Build.h:130:15: Warnung: ?void AsmJit::crash(int*)? definiert, aber nicht verwendet [-Wunused-function]
C:\MinGW\bin\gcc.exe -mdll -O -Wall -Isrc/dyncall/include -Isrc/DynDetours/include -Isrc/ASMJit -Isrc/testlib -IC:\Python25\i
nclude -IC:\Python25\PC -c src/binutils_python.cpp -o build\temp.win32-2.5\Release\src\binutils_python.o -fvisibility=hidden
-fvisibility-inlines-hidden
writing build\temp.win32-2.5\Release\src\binutils_C.def
C:\MinGW\bin\g++.exe -shared -s build\temp.win32-2.5\Release\src\binutils_main.o build\temp.win32-2.5\Release\src\binutils_sc
anner.o build\temp.win32-2.5\Release\src\binutils_hooks.o build\temp.win32-2.5\Release\src\binutils_python.o build\temp.win32
-2.5\Release\src\binutils_C.def -Lsrc/dyncall/lib -Lsrc/DynDetours/lib -Lsrc/ASMJit/lib -LC:\Python25\libs -LC:\Python25\PCBu
ild -llibdyncall_s -llibdynload_s -lDynDetours -lAsmJit -lpython25 -lmsvcr71 -o binutils_C.pyd -static-libgcc -static-libstdc
++
Warning: .drectve `/DEFAULTLIB:"LIBCMT" /DEFAULTLIB:"OLDNAMES" ' unrecognized
Warning: .drectve `/DEFAULTLIB:"LIBCMT" /DEFAULTLIB:"OLDNAMES" ' unrecognized
Warning: .drectve `/DEFAULTLIB:"LIBCMT" /DEFAULTLIB:"OLDNAMES" ' unrecognized
Warning: .drectve `/DEFAULTLIB:"LIBCMT" /DEFAULTLIB:"OLDNAMES" ' unrecognized
Warning: .drectve `/DEFAULTLIB:"uuid.lib" /DEFAULTLIB:"uuid.lib" /DEFAULTLIB:"LIBCMT" /DEFAULTLIB:"OLDNAMES" ' unrecognized
build\temp.win32-2.5\Release\src\binutils_main.o:binutils_main.cpp :( .text+0x17d): undefined reference to `_g_DetourManager'
build\temp.win32-2.5\Release\src\binutils_main.o:binutils_main.cpp :( .text+0x182): undefined reference to `CDetourManager::Fin
d_Detour(void*)'
build\temp.win32-2.5\Release\src\binutils_main.o:binutils_main.cpp :( .text+0x204): undefined reference to `_g_DetourManager'
build\temp.win32-2.5\Release\src\binutils_main.o:binutils_main.cpp :( .text+0x209): undefined reference to `CDetourManager::Fin
d_Detour(void*)'
build\temp.win32-2.5\Release\src\binutils_main.o:binutils_main.cpp :( .text+0x22f): undefined reference to `CDetour::GetManager
(char const*, eHookType)'
build\temp.win32-2.5\Release\src\binutils_main.o:binutils_main.cpp :( .text+0x2e5): undefined reference to `_g_DetourManager'
build\temp.win32-2.5\Release\src\binutils_main.o:binutils_main.cpp :( .text+0x2ea): undefined reference to `CDetourManager::Add
_Detour(void*, char const*, eCallConv)'
build\temp.win32-2.5\Release\src\binutils_main.o:binutils_main.cpp :( .text+0x305): undefined reference to `CDetour::GetManager
(char const*, eHookType)'
build\temp.win32-2.5\Release\src\binutils_main.o:binutils_main.cpp :( .text+0x346): undefined reference to `CDetour::AddManager
(ICallbackManager*, eHookType)'
build\temp.win32-2.5\Release\src\binutils_hooks.o:binutils_hooks.cpp :( .text+0xb5): undefined reference to `CFuncObj::GetStack
()'
build\temp.win32-2.5\Release\src\binutils_hooks.o:binutils_hooks.cpp :( .text+0x104): undefined reference to `CFuncStack::GetAr
gument(int)'
build\temp.win32-2.5\Release\src\binutils_hooks.o:binutils_hooks.cpp :( .text+0x1a0): undefined reference to `CFuncObj::GetNumA
rgs()'
build\temp.win32-2.5\Release\src\binutils_hooks.o:binutils_hooks.cpp :( .text+0x1d5): undefined reference to `CFuncObj::GetStac
k()'
build\temp.win32-2.5\Release\src\binutils_hooks.o:binutils_hooks.cpp :( .text+0x23d): undefined reference to `CFuncStack::GetAr
gument(int)'
build\temp.win32-2.5\Release\src\binutils_hooks.o:binutils_hooks.cpp :( .text+0x301): undefined reference to `CFuncObj::GetNumA
rgs()'
collect2.exe: Fehler: ld gab 1 als Ende-Status zur?ck
error: command 'g++' failed with exit status 1
After searching for the reason, I found a plausible answer. Since DynDetours was compiled with MS VC++ the name mangling is different to MingW's name mangling. Is this the reason? I yes, what could I do? Writing a wrapper? I tried that, but without success. After that I wrote a testlib:
Code: Select all
// testlib.h
extern "C" int squareit(int x);
Code: Select all
#include "testlib.h"
int squareit(int x)
{
return x * x;
}
But the error is still the same: undefine reference to _squareit(int)
I'm out of ideas!

Ayuto