Unable to run the demos "out of the box" using CMake and Visual Studio 2017.

34 views
Skip to first unread message

Vaillancourt

unread,
Aug 17, 2020, 5:46:22 PM8/17/20
to ode-users
Hello!

I have issues when I try to build ("INSTALL") and run ODE demos with CMake and Visual Studio 2017 "out of the box". I have tried with the the branch 0.16.x and master branch.

Note that the command I use to generate my solution, along with the cache variables I use for CMake are at the bottom of this post.

When I try the 0.16.x branch, I can compile and link fine (when I "build the INSALL project"), but when I try to run a demo, it tells me "could not load accelerators". This appears to be related to loading of the resources, a change makes this go through and allows me to run the demos:

c:\ode\ode-master>git diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b105b9a5..01bc6b4a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -767,7 +767,7 @@ if(ODE_WITH_DEMOS)

        foreach(DEMO_SRC ${DEMO_SRCS})
                get_filename_component(DEMO ${DEMO_SRC} NAME_WE)
-               add_executable(${DEMO} ${DEMO_SRC})
+               add_executable(${DEMO} ${DEMO_SRC} drawstuff/src/resources.rc)
                target_link_libraries(${DEMO} drawstuff)

                if(NOT WIN32 AND ${DEMO} MATCHES "demo_chain1")


Now when I try the master branch, when I "build the INSALL project" in the Visual Studio generated solution, I get link errors when it tries to link the demos. The errors appears to be related to the fact that it tries to build a "gui" application instead of a console application.


Here is a sample from Visual Studio's output window:

------ Build started: Project: demo_I, Configuration: Debug Win32 ------
Build started 2020-08-17 15:46:29.
Target ResolveProjectReferences:
Target InitializeBuildStatus:
  Touching "demo_I.dir\Debug\demo_I.tlog\unsuccessfulbuild".
Target CustomBuild:
  Building Custom Rule C:/ode/ode-master/CMakeLists.txt
  CMake does not need to re-run because C:\DevTools\OpenDynamicsEngine-master-double-opcode\build14\x86\CMakeFiles\generate.stamp is up-to-date.
Target ClCompile:
  demo_I.cpp
Target ResolvedLinkLib:
Target Link:
  MSVCRTD.lib(exe_winmain.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
  C:\DevTools\OpenDynamicsEngine-master-double-opcode\build14\x86\Debug\demo_I.exe : fatal error LNK1120: 1 unresolved externals
Done building target "Link" in project "demo_I.vcxproj" -- FAILED.


Applying the following change "solves" the linking issue:

c:\ode\ode-master>git diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 59ed299d..2f5dc4a2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -771,7 +771,7 @@ if(ODE_WITH_DEMOS)
                if(NOT WIN32 OR ${DEMO} STREQUAL "demo_ode")
                        add_executable(${DEMO} ${DEMO_SRC})
                else()
-                       add_executable(${DEMO} WIN32 ${DEMO_SRC})
+                       add_executable(${DEMO} ${DEMO_SRC})
                endif()
                target_link_libraries(${DEMO} drawstuff)
                
                
But I still can't run a demo: when I start it from the VS Debug > Start Debugging command, a message box appears, telling me "could not load accelerators". Again, this appears to be related to loading of the resources, and applying the same change as suggestd above makes this go through:

c:\ode\ode-master>git diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 59ed299d..490031b1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -771,7 +771,7 @@ if(ODE_WITH_DEMOS)
                if(NOT WIN32 OR ${DEMO} STREQUAL "demo_ode")
                        add_executable(${DEMO} ${DEMO_SRC})
                else()
-                       add_executable(${DEMO} WIN32 ${DEMO_SRC})
+                       add_executable(${DEMO} ${DEMO_SRC} drawstuff/src/resources.rc)
                endif()
                target_link_libraries(${DEMO} drawstuff)



With that, the message box I now get tells me: AllocConsole failed(). Since I told VS to start the demo as a console application, I suspect that the app can't start a console twice, so a fix to this:

diff --git a/drawstuff/src/windows.cpp b/drawstuff/src/windows.cpp
index 50c8111a..c225f0fc 100644
--- a/drawstuff/src/windows.cpp
+++ b/drawstuff/src/windows.cpp
@@ -686,7 +686,7 @@ HWND getConsoleHwnd()
 static
 void allocateConsole()
 {
-    if (!AllocConsole()) {
+    if (!getConsoleHwnd() && !AllocConsole()) {
         dsError("AllocConsole() failed");
     }


It appears that I can find my way around those issues, so if there are no correct solution to this, I'll still be able to run the demos, but this all does not seems OK to me. Am I doing things the 'expected' way here?

I get the same behaviour whether I use cmake-3.7.2 (the first version of CMake where the VS2017 generator is available) or cmake-3.18.1 (the most recent available at the moment).

Thanks!

Commands used from a windows cmd window:

set PATH=%PATH%;C:\DevTools\cmake-3.7.2\bin
set PATH=%PATH%;C:\DevTools\git-2.28.0\bin
cd c:\ode
git clone https://bitbucket.org/odedevs/ode.git ode-master

cmake -BC:/DevTools/OpenDynamicsEngine-master-double-opcode/build14/x86/ -Hc:\ode\ode-master -Cc:\ode\cache_vc141x86-double-opcode.txt -G "Visual Studio 15 2017" -T v141



CMake cache file content (cache_vc141x86-double-opcode.txt):

SET( BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries." )
SET( ODE_DOUBLE_PRECISION ON CACHE BOOL "Use double-precision math." )
SET( ODE_WITH_DEMOS ON CACHE BOOL "Builds the demo applications and DrawStuff library." )
SET( ODE_WITH_GIMPACT OFF CACHE BOOL "Use GIMPACT for trimesh collisions (experimental)." )
SET( ODE_WITH_OPCODE ON CACHE BOOL "Use old OPCODE trimesh-trimesh collider." )
SET( CMAKE_INSTALL_PREFIX "C:/DevTools/OpenDynamicsEngine-0.16.2-double-opcode/install14/x86" CACHE PATH "Install path prefix, prepended onto install directories." )



-- Vaillancourt


Oleh Derevenko

unread,
Sep 27, 2020, 8:27:51 AM9/27/20
to ode-...@googlegroups.com

Hi

I do not find -H switch in CMake command line options with a meaning other than

 

--help,-help,-usage,-h,-H,/? = Print usage information and exit.

 

Oleh Derevenko

-- Skype with underscore
GPG Key Fingerprint: 2F56 32DC DCD9 B2BB 06E9 39E8 A37E 5E60 376E C691

openpgp-digital-signature.asc

Oleh Derevenko

unread,
Sep 27, 2020, 1:58:03 PM9/27/20
to ode-...@googlegroups.com

Hi Vaillancourt,

 

The issues you reported have been fixed. The changes are available both in ‘main’ and ‘0.16.x’ branches.
Thank you for letting know about it.

Oleh Derevenko

-- Skype with underscore
GPG Key Fingerprint: 2F56 32DC DCD9 B2BB 06E9 39E8 A37E 5E60 376E C691

 

From: ode-...@googlegroups.com <ode-...@googlegroups.com> On Behalf Of Vaillancourt
Sent: Tuesday, August 18, 2020 12:46 AM
To: ode-users <ode-...@googlegroups.com>
Subject: [ode-users] Unable to run the demos "out of the box" using CMake and Visual Studio 2017.

 

Hello!

openpgp-digital-signature.asc

Vaillancourt

unread,
Oct 13, 2020, 9:07:13 PM10/13/20
to ode-users
Hi Oleh!


I do not find -H switch in CMake command line options with a meaning other than

 

--help,-help,-usage,-h,-H,/? = Print usage information and exit.

 



I assume that you have figured by now that it's the location of the source where the CMakeLists.txt resides. I suppose it's a running gag at kitware to not document this switch...

- Vaillancourt

Vaillancourt

unread,
Oct 13, 2020, 9:45:26 PM10/13/20
to ode-users
Hi Oleh! I have tested them and it seems to work as expected, thanks a lot!

- Vaillancourt
Reply all
Reply to author
Forward
0 new messages