Open AlexFundorin opened 6 years ago
I think there are two options:
set(NANOGUI_BUILD_SHARED OFF CACHE BOOL " " FORCE)
(see compilation docs for other settings). Since you'd be linking against a static library, DLLs shouldn't be an issue as far as NanoGUI goes.CMAKE_RUNTIME_OUTPUT_DIRECTORY
which will in turn make it so that the NanoGUI DLL is in the same directory as your executables. See the wrapup discussion starting here.I vaguely remember there being some issues with static VS 2017 builds but don't remember, if so (2) should be enough. Hope that helps!
For some reason, I can only build x86-Debug static library with the provided solution in VS: https://i.imgur.com/CdPrMtY.png
x86 debug - https://i.imgur.com/y17OLfr.png x86 release - https://i.imgur.com/ZsXMcHe.png x64 debug - https://i.imgur.com/qlU81NP.png x64 release - https://i.imgur.com/ypBbFdC.png
UPD. Deleting nanogui folder and importing the library into VS from GH again, helped. I'll now try to use the lib in my main project. Thanks.
I'm now getting these errors, when trying to import example2's code into my main project, as a test:
#include <nanogui/nanogui.h>
and using namespace nanogui;
are used in the header
UPD: Fixed most of the errors with adding nanogui:: in front of the objects, like "ref" and "Color" which were ambiguous. The remaining error for now is Eigen part: https://i.imgur.com/JE2Aw1G.png And, for some reason, object "c" has only members 'r', 'b' and 'g', but not 'w': https://i.imgur.com/kOigw2f.png UPD. Found "Eigen" folder in the repo "ext" folder. It seems like it's contents weren't incuded into nanogui.lib static library during the compilation process. How do I fix this issue?
Compare your CMakeLists.txt
to the Default Configurations and the Required Variables Exposed section. Are you doing include_directories(${NANOGUI_EXTRA_INCS})
? That is where Eigen should come from, you don't need to include it yourself in your project.
I'm using default, unedited CMakeLists..txt from this repo in VS2017. The only part I've changed is the following
option(NANOGUI_BUILD_SHARED "Build NanoGUI as a shared library?" ON)
option(NANOGUI_BUILD_PYTHON "Build a Python plugin for NanoGUI?" OFF)
option(NANOGUI_USE_GLAD "Use Glad OpenGL loader library?" ${NANOGUI_USE_GLAD_DEFAULT})
option(NANOGUI_INSTALL "Install NanoGUI on `make install`?" OFF)```
I've already checked every mention of ```include_directories``` in the whole repo and didn't found anything wrong.
As I said, I've used the default cmake list for the static library generation.
I guess that this is the part where external libs are included. https://i.imgur.com/PLH3hvj.png
And here it is in the nanogui's folder - https://i.imgur.com/mRFH1Uu.png
Am I doing it right?
Am I doing it right?
No x0 You do not modify the NanoGUI CMakeLists.txt
at all. It seems like you may be new to CMake projects, here's a brief overview.
your_repo/
CMakeLists.txt <-- The parent project build system
ext/
nanogui/
CMakeLists.txt <-- The NanoGUI build system
Where ext/nanogui
should be a git submodule. In your parent project's build system you just do this:
# Disable building extras we won't need (pure C++ project)
set(NANOGUI_BUILD_EXAMPLE OFF CACHE BOOL " " FORCE)
set(NANOGUI_BUILD_PYTHON OFF CACHE BOOL " " FORCE)
set(NANOGUI_INSTALL OFF CACHE BOOL " " FORCE)
# you could add the NANOGUI_BUILD_SHARED part here
# Add the configurations from nanogui
add_subdirectory(ext/nanogui) # this executes ext/nanogui/CMakeLists.txt for you
# For reliability of parallel build, make the NanoGUI targets dependencies
set_property(TARGET glfw glfw_objects nanogui PROPERTY FOLDER "dependencies")
# Various preprocessor definitions have been generated by NanoGUI
add_definitions(${NANOGUI_EXTRA_DEFS})
# On top of adding the path to nanogui/include, you may need extras
include_directories(ext/nanogui/include) # make sure you have this
include_directories(${NANOGUI_EXTRA_INCS}) # where GLFW, Eigen, etc come from
# Compile a target using NanoGUI
add_executable(myTarget myTarget.cpp) # <-- your code
# Lastly, additional libraries may have been built for you. In addition to linking
# against NanoGUI, we need to link against those as well.
target_link_libraries(myTarget nanogui ${NANOGUI_EXTRA_LIBS})
FWIW, until you get things working reliably, I encourage you to build from the command line. If you had myTarget.cpp
and copy-paste example2.cpp
's code in there exactly (you should not need to change it), open Visual Studio only after you can get things to compile. I don't know for sure, but I'd be willing to bet the visual studio .sln
needs to be regenerated while you're working this out. See the windows section for building with cmake --build
. The only difference is that here you are building the parent project (so not cd nanogui
, just cd your_repo
.
I'm happy to help you figure this out, but please stop using pictures. Instead, paste code or error messages here. For markdown, you use three backticks to start / end code. You can replace cmake
on the first part with e.g. cpp
or console
or just leave it blank for no syntax highlighting.
```cmake
# ... paste your code here
```
What if I don't have a parent project? How do I build nanogui as a static library, so that all those external lilbraries will also be available, once I decide to add nanogui to one of my project? Or will it still be necessary to add all those libraries separately? Can you, please, provide a step by step tutorial? We've spent about three hours today with a guy who's much more experienced with C++ than me and still couldn't figure out of how to properly add nanogui to my project. I was forced to install eigen and other libraries via vcpkg as static so that nanogui could at least stop complaining. Yet, I've got an error at the compilation process, same as here - https://github.com/wjakob/nanogui/issues/310 I wish there was some easier way to use nanogui in your projects.
I suggest you hold tight and watch this repository. I've been working slowly on getting the install logic working, about two months in the works on and off. I will be opening a PR soon that will enable you to install Nanogui correctly to use as you desire. You will be able to consume it using the more common CMake idioms, find_package(nanogui REQUIRED)
followed by target_link_libraries(your-exe PUBLIC nanogui::nanogui)
. I'm waiting to see if something else merges because it'll cause conflicts that are hard to resolve given the changes (hard to rebase in the git sense), but easy to incorporate manually.
I'll do my best to remember to CC you on the PR, we'll need lots of user testing! But if you watch the repository GitHub should also send an email when new issues / pull requests are open.
I have a few loose ends on that PR, really just need to update the docs and squash some warnings.
Clarification: hang tight as in continue building nanogui as a child project via add_subdirectory
. What you currently run into is the current install is missing more than just not installing headers. There are some compile time definitions that are needed as well. It is possible to get around this, but instead of providing instructions you will be much better served to wait for the new build system.
Also, I'll reopen this so that I know to reference it from the PR when I open it and therefore know to CC you :)
Looking forward to it. Would be also great if you could provide a VS solution/project with all necessary configurations.
Is there an update on this? I'd love to be able to include nanogui simply through vcpkg. Looking forward to any new info on the topic!
Is it possible to use nanogui as a static library for my DLL project? What steps should be performed to do so? I'm using VS2017 to build my main project, if it's important.