Open3D icon indicating copy to clipboard operation
Open3D copied to clipboard

Building static runtime

Open Jason420Git opened this issue 8 years ago • 11 comments

Describe the bug By setting USE_SHARED_LIBS to OFF and MSVC RUNTIME DLL to OFF in CMake I am unable to get the generated project to be configured to build statically. Setting shared libs to off does not seem to change anything. e.g. In Debug if I select the properties of the project it says Multi-Threaded Debug DLL - When I just want MTd). I can set all of these manually which works but this is not suitable if I rebuild the project many times.

To Reproduce Run Cmake in Windows and open in Visual Studio 2015. Look at the properties of the build for the Open3D project.

Desktop (please complete the following information):

  • OS: Windows 10 - Visual Studio 2015

Jason420Git avatar Sep 13 '18 15:09 Jason420Git

@yxlao can you address this?

qianyizh avatar Sep 14 '18 06:09 qianyizh

With:

cmake -DUSE_MSVC_RUNTIME_LIBRARY_DLL=OFF USE_SHARED_LIBS=OFF -DPYTHON_EXECUTABLE=path-to-my-python -G "Visual Studio 15 2017 Win64" ..

With the debug config, I am getting all static libs in build\lib\Debug after building the ALL_BUILD target in Visual Studio.

$ dir
 Volume in drive C has no label.
 Volume Serial Number is 5410-C979

 Directory of C:\Users\linux\repo\Open3D\build\lib\Debug

09/18/2018  05:50 PM    <DIR>          .
09/18/2018  05:50 PM    <DIR>          ..
09/18/2018  05:49 PM         1,702,744 glew.lib
09/18/2018  05:47 PM           135,168 glew.pdb
09/18/2018  05:49 PM           897,020 glfw3.lib
09/18/2018  05:49 PM           970,172 jpeg.lib
09/18/2018  05:47 PM           143,360 jpeg.pdb
09/18/2018  05:49 PM         5,175,420 jsoncpp.lib
09/18/2018  05:47 PM           888,832 jsoncpp.pdb
09/18/2018  05:50 PM       181,112,198 Open3D.lib
09/18/2018  05:50 PM           577,536 Open3D.pdb
09/18/2018  05:49 PM           998,174 png.lib
09/18/2018  05:49 PM           159,744 png.pdb
09/18/2018  05:49 PM           134,500 tinyfiledialogs.lib
09/18/2018  05:49 PM           102,400 tinyfiledialogs.pdb
09/18/2018  05:49 PM           272,098 zlib.lib
09/18/2018  05:47 PM            94,208 zlib.pdb
              15 File(s)    193,363,574 bytes
               2 Dir(s)  11,548,184,576 bytes free

After building the project, did you get some .dll generated instead of static libs? Or, it would be great you could provide a screenshot of what you got in the Visual Studio project properties. Thanks.

yxlao avatar Sep 19 '18 01:09 yxlao

No I get .lib files generated. However, when I right click on one of the projects for example Core I get the following setup:

These are my Cmake settings:

cmake

Then my VS project

vs

As you can see the runtime is DLL.

I add Open3D to my project with the following CMAKE commands:

find_package(Open3D REQUIRED)
if(Open3D_FOUND)
	message(STATUS "Found Open3D ${Open3D_VERSION}")
	include_directories(${Open3D_INCLUDE_DIRS})
	link_directories(${Open3D_LIBRARY_DIRS})
	set(Optional_LIBS_PROCESSING ${Optional_LIBS_PROCESSING} ${Open3D_LIBRARIES})
	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${Open3D_C_FLAGS}")
  	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Open3D_CXX_FLAGS}")
    	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${Open3D_EXE_LINKER_FLAGS}")
else()
	message(SEND_ERROR "Open3D not found!")
endif(

And I end up with the following result:

capture

Where the Open3D runtime is dynamic, where as my project is setup for static.

Jason420Git avatar Sep 19 '18 20:09 Jason420Git

Thanks for the screenshots. I got the same "Multi-Threaded Debug DLL" as shown in your screenshots by default.

We have a test program "TestVisualizer" that links to the installed Open3D. You may find its CMake file for reference. The command to build the test program can be found in our CI scripts. Below is the config for "TestVisualizer" and "Open3D". Both of them got "Multi-Threaded Debug DLL" by default. virtualbox_isl_w10_64_20_09_2018_10_02_05

According to this post, the runtime C library that Open3D links to must be the same as the one that your application links to. USE_SHARED_LIBS only controls whether Open3D is built as "static" or "dynamic" library, which seems unrelated to the issue here. Maybe you could check the C runtime your application is using?

yxlao avatar Sep 20 '18 17:09 yxlao

Hi, the project I have is setup to use the MTd runtime. Which is why it complains about Open3D. Is there a way to set the runtime of Open3D to be static in its Cmake? I am not 100% sure that I understand your solution. Thanks

Jason420Git avatar Sep 23 '18 16:09 Jason420Git

Hi,

I am still having trouble with this. It also does not create separate debug and release libs. So I need to build it, rename the libs and build again. This is okay if it is once in a while but since the library is changing quickly I need to do this several times.

Jason420Git avatar Oct 18 '18 09:10 Jason420Git

@Jason420Git We're working on the 0.4 release now, will revisit this issue soon after the release

yxlao avatar Oct 19 '18 15:10 yxlao

@Jason420Git We're working on the 0.4 release now, will revisit this issue soon after the release

Great thank you! Looking forward to it. I have transitioned my code over from PCL to Open3D and this is the only final thing that I am having trouble with, before I can make a full switchover.

Jason420Git avatar Oct 20 '18 16:10 Jason420Git

I apologise for pestering but I am eagerly awaiting this change. 0.4 is now released and I have been able to use it successfully, is there an estimate on when this issue wiill be worked on?

Many thanks!

Jason420Git avatar Nov 01 '18 10:11 Jason420Git

@yxlao can you follow up on this?

qianyizh avatar Nov 02 '18 05:11 qianyizh

@Jason420Git @qianyizh shall be resolved by #661

yxlao avatar Nov 06 '18 01:11 yxlao