NVIDIAGameWorks / FleX

Other
650 stars 100 forks source link

Issue with SDL 2.0.4 with creating Python bindings for FleX #62

Open henryclever opened 5 years ago

henryclever commented 5 years ago

Hi all,

I'm in the process of creating Python bindings for FleX using Pybind11. So far, I've been able to link many of the FleX libraries (static .a libraries, header .h files, .cpp files...) correctly. However, I'm having an issue linking the static libraries from SDL. I get the following error:

/usr/bin/ld: /home/henry/git/FleX_pose_estimation/external/SDL2-2.0.4/lib/x64/libSDL2.a(SDL_dynapi.o): relocation R_X86_64_32S against `.data' can not be used when making a shared object; recompile with -fPIC
    /home/henry/git/FleX_pose_estimation/external/SDL2-2.0.4/lib/x64/libSDL2.a: error adding symbols: Bad value
    collect2: error: ld returned 1 exit status

I can correctly link the libSDL2_test.a and libSDL2main.a libraries but the python binding requires functions defined in the libSDL.a library. I believe that SDL2-2.0.4 needs to be recompiled using the -fPIC CMAKE flag. Could someone post the present code that is used to compile SDL2 for FleX? That way, perhaps I can edit it a bit and massage the library to where I want without breaking things.

I plan to release these bindings publicly for general use cases, in addition to the case more specific to my research.

Thanks! Henry C.

henryclever commented 5 years ago

I think I've fixed the issue. Here is what I did:

I downloaded SDL 2.0.4: https://www.libsdl.org/release/ First, I added the flag -fPIC to line 151 of CMakeLists.txt in SDL2-2.0.4. I changed it to: set(CMAKE_C_FLAGS "-g -O3 -fPIC").

Next, I commented out line 823 of CMakeLists.txt in SDL2-2.0.4 - it previously was CheckWayland(). Wayland causes a make error when you are compiling SDL2-2.0.4, and I don't think you need it.

Then I built SDL2-2.0.4. (mkdir build, cd build, cmake .. , make -j4). I replaced the following file: FleX/external/SDL2-2.0.4/lib/x64/libSDL2.a with the new libSDL2.a file I created in the build folder of my CMakeLists-modded SDL2.0.4. My replacement is slightly bigger (10.6MB vs 9.6MB).

I re-compiled the C++ code and restarted the demo, and it all works! Got lucky on this one. My pybinding also links things correctly now.

Warmth, Henry C.

sadernalwis commented 5 years ago

Hello Henry, I had the same issue and I recompiled with newly built modded libSDL2.a. The compilation is successful but when I run both Debug and Release I get the

./NvFlexDemoDebugCUDA_x64
Reshaping
*** stack smashing detected ***: <unknown> terminated
Aborted (core dumped)

maybe you can help me with this. Thank you Sadern

sadernalwis commented 5 years ago

the shipped binaries run very well. but when I try to compile the demo: the problem is at Initialization of the Flex library.

line 3247 demo/main.cpp

g_flexLib = NvFlexInit(NV_FLEX_VERSION, ErrorCallback, &desc);

https://github.com/NVIDIAGameWorks/FleX/blob/78decdfaa99c1d51513683f4407ccfcbb7dfb128/demo/main.cpp#L3247

nikepupu commented 2 years ago

same issue here