I have some binary .fic
files in a proprietary format , I have a wd250hf64.so
from this vendor that contains a C++ method CComposanteHyperFile::HExporteXML(wchar_t* const path)
that I can see using nm
$ nm --demangle wd250hf64.so --defined-only
0000000000118c90 t CComposanteHyperFile::HExporteXML(wchar_t const*)
the unmangled version _ZN20CComposanteHyperFile11HExporteXMLEPKw
is identical to what I have using my local g++ version
readelf gives
readelf -Ws wd250hf64.so | grep _ZN20CComposanteHyperFile11HExporteXMLEPK
19684: 0000000000118c90 119 FUNC LOCAL DEFAULT 11 _ZN20CComposanteHyperFile11HExporteXMLEPKw
now I try writing a very simple program
class CComposanteHyperFile {
public:
static void HExporteXML(wchar_t const*);
};
int main() {
CComposanteHyperFile::HExporteXML(L"file.fic");
return 0;
}
but when I compile it with g++ toto.cpp -L. -l:wd250hf64.so
I got toto.cpp:(.text+0x10): undefined reference to 'CComposanteHyperFile::HExporteXML(wchar_t const*)'
I don't have more luck with dlopen
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
int
main(int argc, char **argv)
{
void *handle;
void (*exportXML)(wchar_t const*);
char *error;
handle = dlopen("wd250hf64.so", RTLD_LAZY);
*(void **) (&exportXML) = dlsym(handle, "_ZN20CComposanteHyperFile11HExporteXMLEPKw");
if ((error = dlerror()) != NULL) {
fprintf(stderr, "%s\n", error);
exit(EXIT_FAILURE);
}
dlclose(handle);
exit(EXIT_SUCCESS);
}
gcc -rdynamic -o foo toto.c -ldl
./foo
wd250hf64.so: undefined symbol: _ZN20CComposanteHyperFile11HExporteXMLEPKw
I understand that as it is not shown by nm with --extern-only
it may be that this symbol is not "exported" and so it's not supposed to work normally
my question is
What is the hackish way of making the program to compile, by all means, even if it means manually patching the .so file ?
-l
flag. I.e. it should beg++ toto.cpp -L. -l:wd250hf64.so
. Does this solve the problem? Otherwise, you could always try to load the library dynamically viadlopen
. – Devilryg++ toto.cpp -L. -l:wd250hf64.so
returns the same error – Theismstrip
. – HostilityLD_LIBRARY_PATH
contains the path to your librarywd250hf64.so
? Also, why do you specify a colon:
in the command-l:wd250hf64.so
? – Fourpence:
i.e" g++ toto.cpp -L. -l wd250hf64.so" (with or without the space after the-l
cause a/usr/bin/ld: cannot find -lwd250hf64.so
– TheismLD_LIBRARY_PATH
? – Fourpence.so
in my current directory, and normally -L. is here for that, in any case, I added also the absolute path by re-exportingexport LD_LIBRARY_PATH=$(pwd):$LD_LIBRARY_PATH
but still the same issue – Theism