caffe icon indicating copy to clipboard operation
caffe copied to clipboard

CMake: position independent code on Windows?

Open morrisonlevi opened this issue 8 years ago • 3 comments

Currently the flag -fPIC is being set like this:

if(UNIX OR APPLE)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall")
endif()

CMake has a property for this: POSITION_INDEPENDENT_CODE which can be set globally like this:

set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)

However, this begs the question: is there a reason Windows does not need PIC enabled?

morrisonlevi avatar Oct 17 '17 20:10 morrisonlevi

On Windows position independent code is not used, i.e. compilers do not generate position independent code. DLL: dynamic linking lib: means upon first load of the DLL, the actual memory addresses are computed and resolved by the "dynamic" linker. The actual "positions" are then "patched in" the code...
I think on Win set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) is simply NOP for CMake...

See e.g. this old thread.

LeslieGerman avatar Apr 16 '19 10:04 LeslieGerman

On Windows position independent code is not used, i.e. compilers do not generate position independent code. DLL: dynamic linking lib: means upon first load of the DLL, the actual memory addresses are computed and resolved by the "dynamic" linker. The actual "positions" are then "patched in" the code... I think on Win set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) is simply NOP for CMake...

See e.g. this old thread.

This is false.

trcrsired avatar Jun 04 '22 03:06 trcrsired