undefined reference to <method/object>

General discussion for off-topic subjects.
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

undefined reference to <method/object>

Postby Ayuto » Sat Jan 26, 2013 9:35 am

Hi,

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
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Sat Jan 26, 2013 12:35 pm

Hey Ayuto,

Seems to be a linking problem, at first glance. I'm fairly sure that replacing the lines 45 and 46 of your setup.py with the following ones may fix your compiling issues.[PYTHON] 'libDynDetours',
'libAsmJit',[/PYTHON]If that doesn't works, try to rename both .lib but I'm fairly sure that the right syntax, in that situation, is -llib<library name>.

L'In20Cible
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sat Jan 26, 2013 12:58 pm

Hey L'In20Cible,

thank you for your answer. Unfortunately, it doesn't work. The first suggestion results in the following:

Code: Select all

c:/mingw/bin/../lib/gcc/mingw32/4.7.0/../../../../mingw32/bin/ld.exe: cannot find -llibDynDetours
c:/mingw/bin/../lib/gcc/mingw32/4.7.0/../../../../mingw32/bin/ld.exe: cannot find -llibAsmJit
The second try doesn't change anything. I still get the same error as I described above.
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Fri Feb 01, 2013 7:25 pm

Got it working by compiling everything with MinGW32 and changing some parts of DynDetours (since I'm using ASMJit 1.0 now)!!! :)

Return to “Whatever”

Who is online

Users browsing this forum: No registered users and 17 guests