Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure shared library using MSYS2 for a commercial code #223

Open
a-jp opened this issue Feb 2, 2025 · 76 comments
Open

Ensure shared library using MSYS2 for a commercial code #223

a-jp opened this issue Feb 2, 2025 · 76 comments

Comments

@a-jp
Copy link

a-jp commented Feb 2, 2025

Hi,

I'd like to use (unmodified) CppAD within a commercial closed source code that I distribute. To comply with EPL2.0 I must (for practical purposes) link to a shared library, as static libraries require me to provide a mechanism for the person at the other end to link to a different version of the cppad libraries if they wish, which is practically very challenging while keeping the source closed.

There is a section in the cmakelists:

IF( is_msys OR is_cygwin OR is_windows )
   IF( NOT cppad_static_lib )
      MESSAGE(WARNING
"This systems uses windows dynamic libraries.
The cppad library must be static for this case.
Ignoring fact that cppad_static_lib is FALSE.
"
      )
   ENDIF( )
   SET(is_cppad_lib_dynamic 0)
ELSE( )
   IF( cppad_static_lib )
      SET(is_cppad_lib_dynamic 0)
   ELSE( )
      SET(is_cppad_lib_dynamic 1)
   ENDIF( )
ENDIF( )

If I'm on MSYS2 and request cppad_static_lib to be false, it will be ignored. Is this something that can be reworked, to allow all cppad libs (including the bindings to ipopt also which I use) to be dynamic rather than static?

On a related note, I see on linux that a shared object will be built, but that libcppad_ipopt seems to always be a static library. Again, is this something that could be changed to always be dynamic?

Many thanks,

@bradbell
Copy link
Contributor

bradbell commented Feb 2, 2025

As I recall, *.dll libraries create a separate copy for of the variables that are static in a function, *.so libraries only have one copy for each of these variables.

I suggest you try suppressing the change on MSYS2 and see if the CppAD make checks pass or fail.

@a-jp
Copy link
Author

a-jp commented Feb 2, 2025

I've made the following changes:

$ git diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c7e87cb39..5448cea49 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -573,7 +573,7 @@ Ignoring fact that cppad_static_lib is FALSE.
 "
       )
    ENDIF( )
-   SET(is_cppad_lib_dynamic 0)
+   SET(is_cppad_lib_dynamic 1)
 ELSE( )
    IF( cppad_static_lib )
       SET(is_cppad_lib_dynamic 0)
diff --git a/cppad_ipopt/src/CMakeLists.txt b/cppad_ipopt/src/CMakeLists.txt
index d8673bfbe..7710f1262 100644
--- a/cppad_ipopt/src/CMakeLists.txt
+++ b/cppad_ipopt/src/CMakeLists.txt
@@ -18,7 +18,7 @@ SET(source_list
 )
 # END_SORT_THIS_LINE_MINUS_2

-ADD_LIBRARY(cppad_ipopt ${source_list})
+ADD_LIBRARY(cppad_ipopt SHARED ${source_list})
 set_compile_flags( cppad_ipopt "${cppad_debug_which}" "${source_list}" )

 # install(FILES files... DESTINATION <dir>

I'm a new user to ninja and that is how the code is built. 'make check' is therefore not a command, should I be running 'ninja test'?

@a-jp
Copy link
Author

a-jp commented Feb 2, 2025

As I recall, *.dll libraries create a separate copy for of the variables that are static in a function, *.so libraries only have one copy for each of these variables.

I'm not sure of the point you're making here. Could you explain?

Thanks

@bradbell
Copy link
Contributor

bradbell commented Feb 2, 2025

  1. You can run cmake for ninja or make; see generator on
    https://cppad.readthedocs.io/latest/cmake.html#generator

  2. Don't worry about my point above for now. Just try the following using a version of
    CMakeLists.txt where is_cppad_lib_dynamic has the value 1 on the target system.

    mkdir build
    cd build
    cmake -G "MSYS Makefiles" ..
    make check

@a-jp
Copy link
Author

a-jp commented Feb 2, 2025

Ok thanks for that. I've remade your latest tagged version using the suggestion above using the code diff I've already posted. I've attached the full output of make check. There were 10 failures that I can see, all seem to be that the libraries cannot find system libraries, api-ms-win-crt-string-l1-1-0.dll for example. I believe these are windows system libraries. I have not made any attempt to locate these or add them to any paths - I'm not really sure what they are.

Some of the failures include the ipopt tests against your ipopt wrappers - these are the ones I'm making use of so that's the focus. What would you suggestion to fix these build errors?

make_check_output.txt

@bradbell
Copy link
Contributor

bradbell commented Feb 2, 2025

Is this a Debug or Release build ? If it is a release, try with debugging for more error messaging.

@a-jp
Copy link
Author

a-jp commented Feb 2, 2025

release.

/cppad_ipopt_test.exe: error while loading shared libraries: api-ms-win-crt-string-l1-1-0.dll: cannot open shared object file: No such file or directory

will debugging give more info on the missing library?

@bradbell
Copy link
Contributor

bradbell commented Feb 2, 2025

release.

/cppad_ipopt_test.exe: error while loading shared libraries: api-ms-win-crt-string-l1-1-0.dll: cannot open shared object file: No such file or directory

will debugging give more info on the missing library?

More info. You can run make check_speed_example because that is the check that is failing (with debug info).

@a-jp
Copy link
Author

a-jp commented Feb 2, 2025

using -Dcppad_debug_which="debug_all" now fails to actually build:

[100%] Linking CXX shared library libcppad_lib.dll
[100%] Built target cppad_lib
[100%] Building CXX object cppad_ipopt/src/CMakeFiles/cppad_ipopt.dir/vec_fun_pattern.cpp.obj
[100%] Linking CXX shared library libcppad_ipopt.dll
 C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/cppad_ipopt.dir/objects.a(cppad_ipopt_nlp.cpp.obj): in function `Ipopt::ReferencedObject::ReferencedObject()':
C:/msys64/home/user/codebase/gcc/release/from-git-repo/Ipopt-releases-3.14.16-install/include/coin-or/IpReferenced.hpp:173:(.text$_ZN5Ipopt16ReferencedObjectC2Ev[_ZN5Ipopt16ReferencedObjectC2Ev]+0xb): undefined reference to `__imp__ZTVN5Ipopt16ReferencedObjectE'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/cppad_ipopt.dir/objects.a(cppad_ipopt_nlp.cpp.obj): in function `Ipopt::ReferencedObject::~ReferencedObject()':
C:/msys64/home/user/codebase/gcc/release/from-git-repo/Ipopt-releases-3.14.16-install/include/coin-or/IpReferenced.hpp:177:(.text$_ZN5Ipopt16ReferencedObjectD2Ev[_ZN5Ipopt16ReferencedObjectD2Ev]+0xb): undefined reference to `__imp__ZTVN5Ipopt16ReferencedObjectE'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/cppad_ipopt.dir/objects.a(cppad_ipopt_nlp.cpp.obj): in function `Ipopt::ReferencedObject::~ReferencedObject()':
C:/msys64/home/user/codebase/gcc/release/from-git-repo/Ipopt-releases-3.14.16-install/include/coin-or/IpReferenced.hpp:177:(.text$_ZN5Ipopt16ReferencedObjectD1Ev[_ZN5Ipopt16ReferencedObjectD1Ev]+0xb): undefined reference to `__imp__ZTVN5Ipopt16ReferencedObjectE'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/cppad_ipopt.dir/objects.a(cppad_ipopt_nlp.cpp.obj): in function `Ipopt::TNLP::TNLP()':
C:/msys64/home/user/codebase/gcc/release/from-git-repo/Ipopt-releases-3.14.16-install/include/coin-or/IpTNLP.hpp:61:(.text$_ZN5Ipopt4TNLPC2Ev[_ZN5Ipopt4TNLPC2Ev]+0x1b): undefined reference to `__imp__ZTVN5Ipopt4TNLPE'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/cppad_ipopt.dir/objects.a(cppad_ipopt_nlp.cpp.obj): in function `Ipopt::TNLP::~TNLP()':
C:/msys64/home/user/codebase/gcc/release/from-git-repo/Ipopt-releases-3.14.16-install/include/coin-or/IpTNLP.hpp:65:(.text$_ZN5Ipopt4TNLPD2Ev[_ZN5Ipopt4TNLPD2Ev]+0xf): undefined reference to `__imp__ZTVN5Ipopt4TNLPE'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/cppad_ipopt.dir/objects.a(cppad_ipopt_nlp.cpp.obj): in function `void CppAD::put_check_for_nan<double>(CppAD::vector<double> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
C:/msys64/home/user/codebase/gcc/release/from-git-repo/cppad-20250000.2/include/cppad/core/check_for_nan.hpp:177:(.text$_ZN5CppAD17put_check_for_nanIdEEvRKNS_6vectorIT_EERNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN5CppAD17put_check_for_nanIdEEvRKNS_6vectorIT_EERNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x5a): undefined reference to `CppAD::local::temp_file[abi:cxx11]()'
collect2.exe: error: ld returned 1 exit status
make[2]: *** [cppad_ipopt/src/CMakeFiles/cppad_ipopt.dir/build.make:165: cppad_ipopt/src/libcppad_ipopt.dll] Error 1
make[1]: *** [CMakeFiles/Makefile2:4155: cppad_ipopt/src/CMakeFiles/cppad_ipopt.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

make check_speed_example is not built.

@bradbell
Copy link
Contributor

bradbell commented Feb 2, 2025

Try adding the directory that contains the missing library to your PATH (windows looks for dlls in its path).

@a-jp
Copy link
Author

a-jp commented Feb 2, 2025

Ok, so that is to fix the most recent debug build failing that you asked for?

Or that is to fix api-ms-win-crt-string-l1-1-0.dll link errors in release?

Also, do you know where that location of these can typically be found, it's not a dll I've actively installed? Inside MSYS2 or inside windows?

@bradbell
Copy link
Contributor

bradbell commented Feb 2, 2025

How did you get Ipopt ? The check for nan error means the directory with the lib_cppad.dll may not be in your path.

@a-jp
Copy link
Author

a-jp commented Feb 2, 2025

I just downloaded and compiled it from source under the same process/os/compilers etc

@bradbell
Copy link
Contributor

bradbell commented Feb 2, 2025

There is an option to have cppad get its optional packages and install them locally; see
https://cppad.readthedocs.io/latest/get_optional.sh.html

@a-jp
Copy link
Author

a-jp commented Feb 2, 2025

getting a bit lost with what I should try next. do you have any advice on where I could typically find api-ms-win-crt-string-l1-1-0.dll to add to my path?

I will go back to a release build and ensure ipopt is in the path

@bradbell
Copy link
Contributor

bradbell commented Feb 2, 2025

@a-jp
Copy link
Author

a-jp commented Feb 2, 2025

Thanks. I'll take a look. I'm on windows 11 and already have MSVC installed. It's not clear that it shouldn't be there. But I'll look and get back to this thread.

@bradbell
Copy link
Contributor

bradbell commented Feb 2, 2025

You can get a conda-forege install of cppad on windows; see
https://anaconda.org/conda-forge/cppad

But this uses static libraries. If it turns out form your testing that a dll will work, perhaps that can be changed in the conda-forge version.

@bradbell
Copy link
Contributor

bradbell commented Feb 2, 2025

I have a fix that may avoid some of the linking problems you are having. Start with the original 20250000.2 source and in the top level directory create the file CMakeLists.patch with the contents below. Then execute the command patch CMakeLists.txt CMakeLists.patch . Then make your other changes to CMakeLists.txt.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c7e87cb39..fdef72634 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -472,6 +472,38 @@ FOREACH(dir_types includedirs libdirs datadir docdir)
       SET(cppad_abs_${dir_type} ${cppad_abs_${dir_type}}/${cppad_postfix} )
    ENDIF( cppad_postfix )
 ENDFOREACH(dir_types includedirs libdirs datadir docdir)
+# ----------------------------------------------------------------------------
+# https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling
+#
+# CMAKE_SKIP_BUILD_RPATH
+# use, i.e. don't skip the full RPATH for the build tree
+SET(CMAKE_SKIP_BUILD_RPATH FALSE)
+#
+# CMAKE_BUILD_WITH_INSTALL_RPATH
+# when building shared libraries, don't use the install RPATH already
+# (but later on when installing)
+SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
+#
+# CMAKE_INSTAL_RPATH_USE_LINK_PATH
+# add the automatically determined parts of the RPATH
+# which point to directories outside the build tree to the install RPATH
+SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
+#
+# isSyatemDir
+# is this RPATH choice a system directory
+LIST(FIND
+   CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
+   "${cppad_abs_libdir}"
+   isSystemDir
+)
+#
+# CMAKE_INSTALL_RPATH
+# the RPATH to be used when installing, but only if it's not a system directory
+SET(CMAKE_INSTALL_RPATH "")
+if("${isSystemDir}" STREQUAL "-1")
+   SET(CMAKE_INSTALL_RPATH "${cppad_abs_libdir}")
+endif("${isSystemDir}" STREQUAL "-1")
+print_variable( CMAKE_INSTALL_RPATH )
 # -----------------------------------------------------------------------------
 # OpenMP_CXX_FOUND, OpenMP_CXX_FLAGS
 IF( ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" )

@a-jp
Copy link
Author

a-jp commented Feb 3, 2025

I'm working my way through this I've a full stack to compile before I can be sure. Get back to you. Thanks

@a-jp
Copy link
Author

a-jp commented Feb 7, 2025

Ok, so I've managed to build my code entirely via MSYS2 (ucrt64), in release, run it on windows, that is via a powershell and nothing to do with an MSYS2 shell, and get the same results from my code as run on linux. What I can say is that make check still fails - however, something odd is going on. When I run the exe file from a powershell command, it doesn't print anything to the screen, but does run, but the make check command issued from MSYS2 does fail:

So within MSYS2 terminal using ucrt64:

$ make check
[  0%] Built target cppad_ipopt
[  1%] Built target cppad_lib
[  2%] Building CXX object cppad_ipopt/speed/CMakeFiles/cppad_ipopt_speed.dir/__/src/cppad_ipopt_nlp.cpp.obj
[  2%] Building CXX object cppad_ipopt/speed/CMakeFiles/cppad_ipopt_speed.dir/__/src/hes_fg_map.cpp.obj
[  2%] Building CXX object cppad_ipopt/speed/CMakeFiles/cppad_ipopt_speed.dir/__/src/jac_g_map.cpp.obj
[  2%] Building CXX object cppad_ipopt/speed/CMakeFiles/cppad_ipopt_speed.dir/__/src/sparse_map2vec.cpp.obj
[  2%] Building CXX object cppad_ipopt/speed/CMakeFiles/cppad_ipopt_speed.dir/__/src/vec_fun_pattern.cpp.obj
[  2%] Building CXX object cppad_ipopt/speed/CMakeFiles/cppad_ipopt_speed.dir/ode_speed.cpp.obj
[  2%] Building CXX object cppad_ipopt/speed/CMakeFiles/cppad_ipopt_speed.dir/speed.cpp.obj
[  3%] Linking CXX executable cppad_ipopt_speed.exe
[  3%] Built target cppad_ipopt_speed
C:/msys64/home/user/codebase/cppad-build/cppad_ipopt/speed/cppad_ipopt_speed.exe: error while loading shared libraries: api-ms-win-crt-time-l1-1-0.dll: cannot open shared object file: No such file or directory
                         make[3]: *** [cppad_ipopt/speed/CMakeFiles/check_cppad_ipopt_speed.dir/build.make:70: cppad_ipopt/speed/CMakeFiles/check_cppad_ipopt_speed] Error 127
make[2]: *** [CMakeFiles/Makefile2:4285: cppad_ipopt/speed/CMakeFiles/check_cppad_ipopt_speed.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:1289: CMakeFiles/check.dir/rule] Error 2
make: *** [Makefile:169: check] Error 2

However, going to a powershell and running the exe:

    Directory: C:\msys64\home\user\codebase\cppad-build\cppad_ipopt\speed


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        06/02/2025     11:37                CMakeFiles
-a----        06/02/2025     11:37           1582 cmake_install.cmake
-a----        07/02/2025     13:36        1106277 cppad_ipopt_speed.exe
-a----        06/02/2025     11:37          17984 Makefile


(base) PS C:\msys64\home\user\codebase\cppad-build\cppad_ipopt\speed> .\cppad_ipopt_speed.exe
(base) PS C:\msys64\home\user\codebase\cppad-build\cppad_ipopt\speed>

I'm assuming nothing printed to the screen but otherwise running is a pass here?

I needed the changes you committed and I needed the diff I've noted above, but in this instance I'm not sure running make check is really telling the whole story. For instance if make check just, made the checks, and I was able to 'run check' in the powershell we may see this as a pass.

I would say finally, that a debug build on MSYS2 (ucrt) does not link properly do to missing symbols, so I cannot run the make check process under debug due to that. I noted that build failure above and repeat here for convenience:

[100%] Linking CXX shared library libcppad_lib.dll
[100%] Built target cppad_lib
[100%] Building CXX object cppad_ipopt/src/CMakeFiles/cppad_ipopt.dir/vec_fun_pattern.cpp.obj
[100%] Linking CXX shared library libcppad_ipopt.dll
 C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/cppad_ipopt.dir/objects.a(cppad_ipopt_nlp.cpp.obj): in function `Ipopt::ReferencedObject::ReferencedObject()':
C:/msys64/home/user/codebase/gcc/release/from-git-repo/Ipopt-releases-3.14.16-install/include/coin-or/IpReferenced.hpp:173:(.text$_ZN5Ipopt16ReferencedObjectC2Ev[_ZN5Ipopt16ReferencedObjectC2Ev]+0xb): undefined reference to `__imp__ZTVN5Ipopt16ReferencedObjectE'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/cppad_ipopt.dir/objects.a(cppad_ipopt_nlp.cpp.obj): in function `Ipopt::ReferencedObject::~ReferencedObject()':
C:/msys64/home/user/codebase/gcc/release/from-git-repo/Ipopt-releases-3.14.16-install/include/coin-or/IpReferenced.hpp:177:(.text$_ZN5Ipopt16ReferencedObjectD2Ev[_ZN5Ipopt16ReferencedObjectD2Ev]+0xb): undefined reference to `__imp__ZTVN5Ipopt16ReferencedObjectE'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/cppad_ipopt.dir/objects.a(cppad_ipopt_nlp.cpp.obj): in function `Ipopt::ReferencedObject::~ReferencedObject()':
C:/msys64/home/user/codebase/gcc/release/from-git-repo/Ipopt-releases-3.14.16-install/include/coin-or/IpReferenced.hpp:177:(.text$_ZN5Ipopt16ReferencedObjectD1Ev[_ZN5Ipopt16ReferencedObjectD1Ev]+0xb): undefined reference to `__imp__ZTVN5Ipopt16ReferencedObjectE'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/cppad_ipopt.dir/objects.a(cppad_ipopt_nlp.cpp.obj): in function `Ipopt::TNLP::TNLP()':
C:/msys64/home/user/codebase/gcc/release/from-git-repo/Ipopt-releases-3.14.16-install/include/coin-or/IpTNLP.hpp:61:(.text$_ZN5Ipopt4TNLPC2Ev[_ZN5Ipopt4TNLPC2Ev]+0x1b): undefined reference to `__imp__ZTVN5Ipopt4TNLPE'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/cppad_ipopt.dir/objects.a(cppad_ipopt_nlp.cpp.obj): in function `Ipopt::TNLP::~TNLP()':
C:/msys64/home/user/codebase/gcc/release/from-git-repo/Ipopt-releases-3.14.16-install/include/coin-or/IpTNLP.hpp:65:(.text$_ZN5Ipopt4TNLPD2Ev[_ZN5Ipopt4TNLPD2Ev]+0xf): undefined reference to `__imp__ZTVN5Ipopt4TNLPE'
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/cppad_ipopt.dir/objects.a(cppad_ipopt_nlp.cpp.obj): in function `void CppAD::put_check_for_nan<double>(CppAD::vector<double> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
C:/msys64/home/user/codebase/gcc/release/from-git-repo/cppad-20250000.2/include/cppad/core/check_for_nan.hpp:177:(.text$_ZN5CppAD17put_check_for_nanIdEEvRKNS_6vectorIT_EERNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN5CppAD17put_check_for_nanIdEEvRKNS_6vectorIT_EERNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x5a): undefined reference to `CppAD::local::temp_file[abi:cxx11]()'
collect2.exe: error: ld returned 1 exit status
make[2]: *** [cppad_ipopt/src/CMakeFiles/cppad_ipopt.dir/build.make:165: cppad_ipopt/src/libcppad_ipopt.dll] Error 1
make[1]: *** [CMakeFiles/Makefile2:4155: cppad_ipopt/src/CMakeFiles/cppad_ipopt.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

Would you be content to absorb my changes along side your own? I would add that the shared lib under linux is useful too.

Also, I should probably I have protected the shared build more consistently:

-ADD_LIBRARY(cppad_ipopt ${source_list})
+ADD_LIBRARY(cppad_ipopt SHARED ${source_list})
 set_compile_flags( cppad_ipopt "${cppad_debug_which}" "${source_list}" )

 # install(FILES files... DESTINATION <dir>

Should probably respect the cppad_static_lib flag.

What do you think?

@bradbell
Copy link
Contributor

bradbell commented Feb 7, 2025

I think that this is coming from the following:
https://cppad.readthedocs.io/latest/cppad_ipopt_nlp.html
which has been deprecated for over 10 years (use ipopt_solve instead) but is being tested because cppad_has_ipopt is true; see the following

IF( cppad_has_ipopt )
   ADD_SUBDIRECTORY(cppad_ipopt)
ENDIF( cppad_has_ipopt )

in
https://github.com/coin-or/CppAD/blob/master/CMakeLists.txt
Try removing that section of the top level CMakeLists.txt and see what happens.

@a-jp
Copy link
Author

a-jp commented Feb 7, 2025

This got to 100% with only a few failures (used -k), it's simply because it's running the exe through MSYS2 which doesn't have the api-ms* files. Sorry for the long cut and paste, but here are the results of a release make check on MSYS2 (ucrt64):

$ make check -k 10
[  1%] Built target speed_src
[  2%] Built target cppad_lib
[  4%] Built target speed_xpackage
xpackage_det_lu_available = false
xpackage_det_minor_available = false
xpackage_mat_mul_available = false
xpackage_ode_available = false
xpackage_poly_available = false
xpackage_sparse_hessian_available = false
xpackage_sparse_jacobian_available = false
All 0 correctness tests passed.
speed main: OK
[  4%] Built target check_speed_xpackage
[  6%] Built target speed_cppad
cppad_det_lu_correct =  true
cppad_det_minor_correct =  true
cppad_mat_mul_correct =  true
cppad_ode_correct =  true
cppad_poly_correct =  true
cppad_sparse_hessian_correct =  true
cppad_sparse_jacobian_correct =  true
All 7 correctness tests passed.
speed main: OK
[  6%] Built target check_speed_cppad
[  7%] Built target speed_cppad_jit
C:/msys64/home/user/codebase/cppad-build/speed/cppad_jit/speed_cppad_jit.exe: error while loading shared libraries: api-ms-win-crt-utility-l1-1-0.dll: cannot open shared object file: No such file or directory
                        make[3]: *** [speed/cppad_jit/CMakeFiles/check_speed_cppad_jit.dir/build.make:70: speed/cppad_jit/CMakeFiles/check_speed_cppad_jit] Error 127
make[3]: Target 'speed/cppad_jit/CMakeFiles/check_speed_cppad_jit.dir/build' not remade because of errors.
make[2]: *** [CMakeFiles/Makefile2:3710: speed/cppad_jit/CMakeFiles/check_speed_cppad_jit.dir/all] Error 2
[  9%] Built target speed_double
double_det_lu_correct =  true
double_det_minor_correct =  true
double_mat_mul_correct =  true
double_ode_correct =  true
double_poly_correct =  true
double_sparse_hessian_correct =  true
double_sparse_jacobian_correct =  true
All 7 correctness tests passed.
speed main: OK
[  9%] Built target check_speed_double
[ 11%] Built target speed_example
det_of_minor        OK
det_by_minor        OK
det_by_lu           OK
elapsed_seconds     OK
mat_sum_sq          OK
ode_evaluate        OK
sparse_hes_fun      OK
sparse_jac_fun      OK
speed_test          OK
time_test           OK
Check above to see if all 10 tests passed.
possible exceptions are: elapsed_seconds, speed_test, time_test

[ 11%] Built target check_speed_example
[ 11%] Built target speed_program
double: result = sum_i a[i] * b[i]
size = 20  rate = 109,766,584
size = 40  rate = 45,161,960
size = 60  rate = 36,091,252
size = 80  rate = 27,015,618
size = 100 rate = 21,423,440
[ 11%] Built target check_speed_program
[ 16%] Built target val_graph
Begin test group val_graph
binary_xam          OK
call_xam            OK
cexp_xam            OK
comp_xam            OK
compress_xam        OK
con_xam             OK
csum_xam            OK
cumulative_xam      OK
dead_xam            OK
dis_xam             OK
fold_con_xam        OK
fun2val_xam         OK
pri_xam             OK
renumber_xam        OK
summation_xam       OK
test_ad_double      OK
test_fold           OK
test_fun2val        OK
test_nan            OK
test_opt_call       OK
test_optimize       OK
test_val2fun
Next line should be '0 >= x[0] - x[1] = -1', line after should be 'OK'
0 >= x[0] - x[1] = -1
OK
unary_xam           OK
val2fun_xam         OK
vec_xam             OK
memory_leak         OK
All 26 tests passed.
End test group val_graph
[ 16%] Built target check_val_graph
[ 17%] Built target example_ipopt_solve
C:/msys64/home/user/codebase/cppad-build/example/ipopt_solve/example_ipopt_solve.exe: error while loading shared libraries: api-ms-win-crt-string-l1-1-0.dll: cannot open shared object file: No such file or directory
                               make[3]: *** [example/ipopt_solve/CMakeFiles/check_example_ipopt_solve.dir/build.make:70: example/ipopt_solve/CMakeFiles/check_example_ipopt_solve] Error 127
make[3]: Target 'example/ipopt_solve/CMakeFiles/check_example_ipopt_solve.dir/build' not remade because of errors.
make[2]: *** [CMakeFiles/Makefile2:2852: example/ipopt_solve/CMakeFiles/check_example_ipopt_solve.dir/all] Error 2
[ 19%] Built target example_abs_normal
Begin test group example/abs_norml
abs_eval            OK
abs_min_linear      OK
abs_min_quad        OK
get_started         OK
lp_box              OK
min_nso_linear      OK
min_nso_quad        OK
qp_box              OK
qp_interior         OK
simplex_method      OK
memory_leak         OK
All 11 tests passed.
End test group example/abs_norml
[ 19%] Built target check_example_abs_normal
[ 21%] Built target example_atomic_four_vector
Begin test group example/atomic_four/vector
add                 OK
div                 OK
hes_sparsity        OK
jac_sparsity        OK
mul                 OK
neg                 OK
rev_depend          OK
sub                 OK
memory_leak         OK
All 9 tests passed.
End test group example/atomic_four/vector
[ 21%] Built target check_example_atomic_four_vector
[ 22%] Built target example_atomic_four
[ 23%] Built target example_atomic_four_lin_ode
Begin test group example/atomic_four/lin_ode
forward             OK
rev_depend          OK
reverse             OK
sparsity            OK
memory_leak         OK
All 5 tests passed.
End test group example/atomic_four/lin_ode
[ 23%] Built target check_example_atomic_four_lin_ode
[ 24%] Built target example_atomic_four_mat_mul
Begin test group example/atomic_four/mat_mul
forward             OK
identical_zero      OK
rev_depend          OK
reverse             OK
sparsity            OK
memory_leak         OK
All 6 tests passed.
End test group example/atomic_four/mat_mul
[ 24%] Built target check_example_atomic_four_mat_mul
Begin test group example/atomic
bilinear            OK
dynamic             OK
forward             OK
get_started         OK
norm_sq             OK
memory_leak         OK
All 6 tests passed.
End test group example/atomic
[ 24%] Built target check_example_atomic_four
[ 26%] Built target example_atomic_three
Begin test group example/atomic
base2ad             OK
dynamic             OK
forward             OK
get_started         OK
hes_sparsity        OK
jac_sparsity        OK
mat_mul             OK
norm_sq             OK
reciprocal          OK
rev_depend          OK
reverse             OK
tangent             OK
memory_leak         OK
All 13 tests passed.
End test group example/atomic
[ 26%] Built target check_example_atomic_three
[ 26%] Built target example_atomic_two
Begin test group example/atomic_two
memory_leak         OK
All 1 tests passed.
End test group example/atomic_two
[ 26%] Built target check_example_atomic_two
[ 28%] Built target example_chkpoint_two
Begin test group example/chkpoint_two
base2ad             OK
compare             OK
dynamic             OK
get_started         OK
ode                 OK
memory_leak         OK
All 6 tests passed.
End test group example/chkpoint_two
[ 28%] Built target check_example_chkpoint_two
[ 28%] Built target example_compare_change
Begin test group example/compare_change
compare_change      OK
memory_leak         OK
All 2 tests passed.
End test group example/compare_change
[ 28%] Built target check_example_compare_change
[ 45%] Built target example_general
Begin test group example/general
Add                 OK
AddEq               OK
BenderQuad          OK
BoolFun             OK
Compare             OK
CondExp             OK
Cos                 OK
Cosh                OK
Div                 OK
DivEq               OK
EqualOpSeq          OK
ForOne              OK
ForTwo              OK
Forward             OK
FunCheck            OK
HesLagrangian       OK
HesLuDet            OK
HesMinorDet         OK
HesTimesDir         OK
Hessian             OK
Independent         OK
Integer             OK
Interface2C         OK
JacLuDet            OK
JacMinorDet         OK
Jacobian            OK
LuRatio             OK
Mul                 OK
MulEq               OK
NumericType         OK
OdeStiff            OK
RevOne              OK
RevTwo              OK
Sin                 OK
Sinh                OK
Sqrt                OK
StackMachine        OK
Sub                 OK
SubEq               OK
Tan                 OK
Tanh                OK
TapeIndex           OK
Value               OK
Var2Par             OK
abort_recording     OK
acos                OK
acosh               OK
ad_assign           OK
ad_ctor             OK
ad_fun              OK
ad_in_c             OK
ad_input            OK
ad_output           OK
asin                OK
asinh               OK
atan                OK
atan2               OK
atanh               OK
azmul               OK
base2ad             OK
base2vec_ad         OK
base_require        OK
capacity_order      OK
change_param        OK
complex_poly        OK
con_dyn_var         OK
erf                 OK
erfc                OK
exp                 OK
expm1               OK
fabs                OK
forward_dir         OK
forward_order       OK
fun_assign          OK
fun_property        OK
function_name       OK
interp_onetape      OK
interp_retape       OK
log                 OK
log10               OK
log1p               OK
lu_vec_ad_ok        OK
mul_level           OK
mul_level_ode       OK
near_equal_ext      OK
new_dynamic         OK
num_limits          OK
number_skip         OK
opt_val_hes         OK
pow                 OK
pow_nan             OK
rev_checkpoint      OK
reverse_one         OK
reverse_three       OK
reverse_two         OK
sign                OK
ode_taylor          OK
unary_minus         OK
unary_plus          OK
vec_ad              OK
memory_leak         OK
All 101 tests passed.
End test group example/general
[ 45%] Built target check_example_general
[ 45%] Built target example_get_started
f'(3) computed by CppAD = 142
[ 45%] Built target check_example_get_started
[ 48%] Built target example_graph
C:/msys64/home/user/codebase/cppad-build/example/graph/example_graph.exe: error while loading shared libraries: api-ms-win-crt-string-l1-1-0.dll: cannot open shared object file: No such file or directory
                   make[3]: *** [example/graph/CMakeFiles/check_example_graph.dir/build.make:70: example/graph/CMakeFiles/check_example_graph] Error 127
make[3]: Target 'example/graph/CMakeFiles/check_example_graph.dir/build' not remade because of errors.
make[2]: *** [CMakeFiles/Makefile2:2178: example/graph/CMakeFiles/check_example_graph.dir/all] Error 2
[ 49%] Built target example_jit
C:/msys64/home/user/codebase/cppad-build/example/jit/example_jit.exe: error while loading shared libraries: api-ms-win-crt-string-l1-1-0.dll: cannot open shared object file: No such file or directory
               make[3]: *** [example/jit/CMakeFiles/check_example_jit.dir/build.make:70: example/jit/CMakeFiles/check_example_jit] Error 127
make[3]: Target 'example/jit/CMakeFiles/check_example_jit.dir/build' not remade because of errors.
make[2]: *** [CMakeFiles/Makefile2:2242: example/jit/CMakeFiles/check_example_jit.dir/all] Error 2
[ 51%] Built target example_multi_thread_sthread
gmtime        = 'Fri Feb  7 15:30:20 2025';
cppad_version = 'cppad-20250000.2';
thread_system = 'sthread';
command       = 'C:\msys64\home\user\codebase\gcc-version2\cppad-build\example\multi_thread\sthread\example_multi_thread_sthread.exe get_started';
free_all      = true;
OK            = true;
[ 51%] Built target check_example_multi_thread_sthread
[ 53%] Built target example_multi_thread_openmp
gmtime        = 'Fri Feb  7 15:30:21 2025';
cppad_version = 'cppad-20250000.2';
thread_system = 'openmp';
command       = 'C:\msys64\home\user\codebase\gcc-version2\cppad-build\example\multi_thread\openmp\example_multi_thread_openmp.exe get_started';
free_all      = true;
OK            = true;
[ 53%] Built target check_example_multi_thread_openmp
[ 53%] Built target check_example_multi_thread
[ 56%] Built target example_json
C:/msys64/home/user/codebase/cppad-build/example/json/example_json.exe: error while loading shared libraries: api-ms-win-crt-string-l1-1-0.dll: cannot open shared object file: No such file or directory
                 make[3]: *** [example/json/CMakeFiles/check_example_json.dir/build.make:70: example/json/CMakeFiles/check_example_json] Error 127
make[3]: Target 'example/json/CMakeFiles/check_example_json.dir/build' not remade because of errors.
make[2]: *** [CMakeFiles/Makefile2:2306: example/json/CMakeFiles/check_example_json.dir/all] Error 2
[ 58%] Built target example_optimize
Begin test group example/optimize
compare_op          OK
cumulative_sum      OK
conditional_skip    OK
forward_active      OK
nest_conditional    OK
print_for           OK
reverse_active      OK
re_optimize         OK
memory_leak         OK
All 9 tests passed.
End test group example/optimize
[ 58%] Built target check_example_optimize
[ 58%] Built target example_print_for
v[0] = 0
v[0] + x[0] = 2
  3. + x[0] = 5
check_log: y == 0 which is <= 0
Test passes if four lines above repeat below:
v[0] = 0
v[0] + x[0] = 2
  3. + x[0] = 5
check_log: y == 0 which is <= 0
[ 58%] Built target check_example_print_for
[ 63%] Built target example_sparse
Begin test group example/sparse
ForSparseJac        OK
RevSparseJac        OK
conj_grad           OK
dependency          OK
for_hes_sparsity    OK
for_jac_sparsity    OK
for_sparse_hes      OK
rc_sparsity         OK
rev_hes_sparsity    OK
rev_jac_sparsity    OK
rev_sparse_hes      OK
sparse_hes          OK
sparse_hessian      OK
sparse_jac_for      OK
sparse_jac_rev      OK
sparse_jacobian     OK
sparse_sub_hes      OK
sparsity_sub        OK
sub_sparse_hes      OK
subgraph_hes2jac    OK
subgraph_jac_rev    OK
reverse_subgraph    OK
subgraph_sparsity   OK
memory_leak         OK
All 24 tests passed.
End test group example/sparse
[ 63%] Built target check_example_sparse
[ 68%] Built target example_utility
C:/msys64/home/user/codebase/cppad-build/example/utility/example_utility.exe: error while loading shared libraries: api-ms-win-crt-utility-l1-1-0.dll: cannot open shared object file: No such file or directory
                        make[3]: *** [example/utility/CMakeFiles/check_example_utility.dir/build.make:70: example/utility/CMakeFiles/check_example_utility] Error 127
make[3]: Target 'example/utility/CMakeFiles/check_example_utility.dir/build' not remade because of errors.
make[2]: *** [CMakeFiles/Makefile2:2724: example/utility/CMakeFiles/check_example_utility.dir/all] Error 2
[ 72%] Built target example_valvector
Begin test group example/valvector
ad_join             OK
ad_split            OK
ad_sum              OK
assign              OK
azmul               OK
base_require        OK
binary_op           OK
compare_op          OK
compound_op         OK
condexp             OK
ctor                OK
element             OK
get_started         OK
llsq_obj            OK
math_unary          OK
output              OK
pow                 OK
resize              OK
size                OK
sum                 OK
unary_op            OK
memory_leak         OK
All 22 tests passed.
End test group example/valvector
[ 72%] Built target check_example_valvector
[ 74%] Built target introduction
Begin test group introduction
exp_2               OK
exp_2_cppad         OK
exp_2_for0          OK
exp_2_for1          OK
exp_2_for2          OK
exp_2_rev1          OK
exp_2_rev2          OK
exp_eps             OK
exp_eps_cppad       OK
exp_eps_for0        OK
exp_eps_for1        OK
exp_eps_for2        OK
exp_eps_rev1        OK
exp_eps_rev2        OK
memory_leak         OK
All 15 tests passed.
End test group introduction
[ 74%] Built target check_introduction
[ 92%] Built target test_more_general
C:/msys64/home/user/codebase/cppad-build/test_more/general/test_more_general.exe: error while loading shared libraries: api-ms-win-crt-utility-l1-1-0.dll: cannot open shared object file: No such file or directory
                            make[3]: *** [test_more/general/CMakeFiles/check_test_more_general.dir/build.make:70: test_more/general/CMakeFiles/check_test_more_general] Error 127
make[3]: Target 'test_more/general/CMakeFiles/check_test_more_general.dir/build' not remade because of errors.
make[2]: *** [CMakeFiles/Makefile2:3506: test_more/general/CMakeFiles/check_test_more_general.dir/all] Error 2
[ 93%] Built target test_more_deprecated_chkpoint_one
Begin test group example/chkpoint_one
extended_ode        OK
get_started         OK
mul_level           OK
ode                 OK
memory_leak         OK
All 5 tests passed.
End test group example/chkpoint_one
[ 93%] Built target check_test_more_deprecated_chkpoint_one
[ 95%] Built target test_more_deprecated
[ 98%] Built target test_more_deprecated_atomic_two
Begin test group test_more/deprecated/atomic_two
atomic_sparsity     OK
mat_mul             OK
base2ad             OK
for_sparse_hes      OK
for_sparse_jac      OK
forward             OK
get_started         OK
norm_sq             OK
reciprocal          OK
rev_sparse_hes      OK
rev_sparse_jac      OK
reverse             OK
set_sparsity        OK
tangent             OK
memory_leak         OK
All 15 tests passed.
End test group test_more/deprecated/atomic_two
[ 98%] Built target check_test_more_deprecated_atomic_two
Begin test group test_more/deprecated
old_mat_mul         OK
old_reciprocal      OK
old_tan             OK
old_usead_1         OK
old_usead_2         OK
omp_alloc           OK
track_new_del       OK
zdouble             OK
memory_leak         OK
All 9 tests passed.
End test group test_more/deprecated
[ 98%] Built target check_test_more_deprecated
[ 98%] Built target test_more_compare_c_cpp
correct_det_by_minor: OK
time_det_minor for 2 x 2 matrix = 8.13873e-08
time_det_minor for 4 x 4 matrix = 3.12232e-07
time_det_minor for 6 x 6 matrix = 5.65465e-06
time_det_minor for 8 x 8 matrix = 0.000306198
time_det_minor for 10 x 10 matrix = 0.0276927
[ 98%] Built target check_test_more_compare_c_cpp
[ 98%] Built target test_more_compare_c_c
correct_det_by_minor: OK
time_det_minor for 2 x 2 matrix = 8.1459e-08
time_det_minor for 4 x 4 matrix = 3.10636e-07
time_det_minor for 6 x 6 matrix = 5.6484e-06
time_det_minor for 8 x 8 matrix = 0.000308544
time_det_minor for 10 x 10 matrix = 0.027025
[ 98%] Built target check_test_more_compare_c_c
[ 98%] Built target check_test_more_compare_c
[ 98%] Built target test_more_debug_rel
Begin test_more/debug_rel
thead_alloc         OK
adfun_ctor          OK
memory              OK
All 3 tests passed.
[ 98%] Built target check_test_more_debug_rel
[100%] Built target test_more_cppad_for_tmb
Begin test group test_more/cppad_for_tmb
implicit_ctor                 OK
prefer_reverse                OK
multi_atomic_two              OK
multi_atomic_three            OK
multi_chkpoint_one            OK
multi_chkpoint_two            OK
memory_leak                   OK
All 7 tests passed.
End test group test_more/cppad_for_tmb
[100%] Built target check_test_more_cppad_for_tmb
make[2]: Target 'CMakeFiles/check.dir/all' not remade because of errors.
make[1]: *** [CMakeFiles/Makefile2:1173: CMakeFiles/check.dir/rule] Error 2
make[1]: Target 'check' not remade because of errors.
make: *** [Makefile:169: check] Error 2
make: *** No rule to make target '10'.

Is that what you expected?

@bradbell
Copy link
Contributor

bradbell commented Feb 7, 2025

Try installing this in some local location and see if you can use the cppad_lib.dll with a simple program.

@bradbell
Copy link
Contributor

bradbell commented Feb 7, 2025

I am currently looking into this using conda on windows (conda lets you build with the Visual Studio compiler).

I got it all to compile and run the tests using NMake mafiles, but my first attempt at getting it to link did not work. I think I do not have the correct flags either on compile or link.

@a-jp
Copy link
Author

a-jp commented Feb 8, 2025

Try installing this in some local location and see if you can use the cppad_lib.dll with a simple program.

That's what I was saying, it does work. I've build my main program, built a cpack installer, installed it under windows, and ran it, somewhere totally different from a powershell. It works fine. Just the 'make checks' that do not run from the build dir when they are executed under MSYS2.

@bradbell
Copy link
Contributor

bradbell commented Feb 8, 2025

I got it to work in Conda (all the tests passed). The real trick to getting a test program (outside the cppad build directory) to work (for me) was using vcvarsall.bat and using CMake to compile and link the separate test of the dll:

cmake_minimum_required( VERSION 3.10 )
project( check_install )
#
include_directories( "c:/users/bradl/repo/cppad.git/include" )
link_directories( "c:/users/bradl/repo/cppad.git/build/cppad_lib" )
#
add_executable( get_started get_started.cpp ) 
target_link_libraries(get_started cppad_lib )
add_custom_target(check get_started)

Note that CMake can use unix like paths (even though we are on windows).

copy c:\users\bradl\repo\cppad.git\example\get_started\get_started.cpp .
mkdir build
cd build
cmake -G "NMake Makefiles" ..
nmake check

@a-jp
Copy link
Author

a-jp commented Feb 8, 2025

Yep agreed. As I said in my previous post that's how I compile my code, cmake. I really think the only problem here is MSYS2 when running the tests.

@bradbell
Copy link
Contributor

bradbell commented Feb 8, 2025

I am going to fully test the change on MSYS2 and if it works, change CMakeLists.txt so that it builds dlls on windows.

@a-jp
Copy link
Author

a-jp commented Feb 8, 2025

Ok. Let me know if I can be any help. I used the UCRT64 variant

@bradbell
Copy link
Contributor

bradbell commented Feb 9, 2025

I think you mean to path cppad_ipopt/src/CMakeLists.txt ?

@a-jp
Copy link
Author

a-jp commented Feb 9, 2025

Yep. Or rather, just all targets that are made across the code base should respect the user flag for dynamic or static.

@bradbell
Copy link
Contributor

bradbell commented Feb 9, 2025

cppad_lib and cppad_ipopt are the only two that get installed (and cppad_ipopt has been deprecated for over ten years and perhaps should be removed).

@a-jp
Copy link
Author

a-jp commented Feb 9, 2025

No worries. Just kept them consistent.

@bradbell
Copy link
Contributor

bradbell commented Feb 9, 2025

OK. I think I have it correct now; see
https://github.com/coin-or/CppAD/blob/master/cppad_ipopt/src/CMakeLists.txt

Thanks.

@a-jp
Copy link
Author

a-jp commented Feb 9, 2025

Looks good. Thanks for that. I'll look to write up MSYS2 notes over the next couple of days.

@a-jp
Copy link
Author

a-jp commented Feb 18, 2025

Sorry this took so long.

Download MSYS2, and Only use the UCRT64 framework for these notes. Open from the start menu the UCRT64 variant of MSYS2. Type echo $MSYSTEM, if this doesn't return UCRT64 you've opened the wrong one from the start menu.

Repeat pacman -Suy until no more updates found, close when asked to close the window, and then continue with the command.

Then install:

pacman -S mingw-w64-ucrt-x86_64-gcc
pacman -S mingw-w64-ucrt-x86_64-cmake
pacman -S mingw-w64-ucrt-x86_64-toolchain
pacman -S make

Then after cloning the master of cppad (a build of Ipopt may be required depending on your commands below):

cmake -G "MSYS Makefiles" -B . -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER=gcc -DCMAKE_BUILD_TYPE=Release -Dinclude_ipopt=On -Dcppad_prefix=../cppad-install/ -Dcppad_static_lib=False -S ../cppad Make -j install

Is this any help?

@bradbell
Copy link
Contributor

bradbell commented Feb 20, 2025

@a-jp
Starting with a new install of msys, using ucrt, and replacing your cmake command by the following, I the error at the bottom. Perhaps we need to add some modification to the environment variables ?

pacman -S git
git clone https://github.com/coin-or/CppAD.git cppad.git
cd cppad.git
#
# begin for ipopt
pacman -S patch
pacman -S  mingw-w64-ucrt-x86_64-gcc-fortran
pacman -S  mingw-w64-ucrt-x86_64-lapack
bin/get_ipopt.sh
# end for ipopt
#
export PKG_CONFIG_PATH="$(pwd)/build/prefix/lib/pkgconfig"
ls $PKG_CONFIG_PATH/ipopt.pc
cmake -S .. -B . \
    -G "MSYS Makefiles"  \
    -D CMAKE_CXX_COMPILER=g++ \
    -D CMAKE_C_COMPILER=gcc \
    -D CMAKE_BUILD_TYPE=Release \
    -D include_ipopt=True \
    -D cppad_prefix=$(pwd)/prefix \
    -D cppad_static_lib=False
make -j1 check

...

C:/msys64/home/bradl/cppad.git/build/cppad_ipopt/test/cppad_ipopt_test.exe: error while loading shared libraries: api-ms-win-crt-string-l1-1-0.dll: cannot open shared object file: No such file or directory
     make[3]: *** [cppad_ipopt/test/CMakeFiles/check_cppad_ipopt_test.dir/build.make:70: cppad_ipopt/test/CMakeFiles/check_cppad_ipopt_test] Error 127
make[2]: *** [CMakeFiles/Makefile2:4350: cppad_ipopt/test/CMakeFiles/check_cppad_ipopt_test.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:1289: CMakeFiles/check.dir/rule] Error 2
make: *** [Makefile:169: check] Error 2

@a-jp
Copy link
Author

a-jp commented Feb 20, 2025

I think we said above that we expect this: we need to separate the compilation of the test-target, from running it. If you run cppad_ipopt_test.exe in a powershell - so not a shell from MSYS2 but a new windows powershell, this should run?

@bradbell
Copy link
Contributor

I keep forgetting that this is like cross compiling. Replacing the make j1 check above by

make -j1 example_ipopt_solve

And then opening a powershell window, changing to the cppad.git directory, and executing

dir build\example\ipopt_solve\example_ipopt_solve.exe

I see that the executable is there. But if I try to execute it. I do not get any output. Here is what I expect when executing it:

Begin test group example/ipopt_solve
get_started         OK
ode_inverse         OK
retape              OK
memory_leak         OK
All 4 tests passed.
End test group example/ipopt_solve

@a-jp
Copy link
Author

a-jp commented Feb 20, 2025

Ok, that one I cannot explain, that is very odd

@bradbell
Copy link
Contributor

Would you please try the same test and report what you get.

@a-jp
Copy link
Author

a-jp commented Feb 20, 2025

yep doing that now

@a-jp
Copy link
Author

a-jp commented Feb 20, 2025

same result, runs with no output

@a-jp
Copy link
Author

a-jp commented Feb 20, 2025

Adding a std::cout << "here" << std::endl; at the top of int main inside ipopt_solve.cpp prints nothing - are you sure something is not set to redirect std cout cerr?

@bradbell
Copy link
Contributor

Same thing happens for me with the get_started example (which is much simpler)
https://cppad.readthedocs.io/latest/get_started.cpp.html

At least I get an error message when I execute the program in dos.

@a-jp
Copy link
Author

a-jp commented Feb 20, 2025

PS C:\msys64\home\user\codebase\toolchain\cppad-build\example\ipopt_solve> $env:PATH +=";C:\msys64\home\user\codebase\toolchain\ipopt-install\bin\"
PS C:\msys64\home\user\codebase\toolchain\cppad-build\example\ipopt_solve> $env:PATH +=";C:\msys64\ucrt64\bin"
PS C:\msys64\home\user\codebase\toolchain\cppad-build\example\ipopt_solve> $env:PATH +=";C:\msys64\home\user\codebase\toolchain\mumps-install\bin\"
PS C:\msys64\home\user\codebase\toolchain\cppad-build\example\ipopt_solve> .\example_ipopt_solve.exe
here
Begin test group example/ipopt_solve
get_started         OK
ode_inverse         OK
retape              OK
memory_leak         OK
All 4 tests passed.
End test group example/ipopt_solve

but I got that to work using Powershell (pwsh.exe), version 7.5.0. Using Windows Powershell (powershell.exe), it prints nothing to the screen. I do not understand what is going on!

Nothing prints out on the MSYS2 terminal

@a-jp
Copy link
Author

a-jp commented Feb 20, 2025

@bradbell
Copy link
Contributor

bradbell commented Feb 21, 2025

Perhaps we should try building a Debug version and see what happens ?
I tried it and was hoping for an assert message, but the result was that same as before.

@a-jp
Copy link
Author

a-jp commented Feb 21, 2025

Can you try the new version of powershell from Microsoft pwsh.exe and prove that using that it works fine? I got it for free from the Microsoft store and using it the program runs fine.

@a-jp
Copy link
Author

a-jp commented Feb 21, 2025

OK, please carefully read this, I've resolved the issue and it works just fine in normal Windows Powershell (powershell.exe)

PS C:\msys64\home\user\codebase\toolchain\cppad-build> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      26100  2161


PS C:\msys64\home\user\codebase\toolchain\cppad-build> .\example\ipopt_solve\example_ipopt_solve.exe
PS C:\msys64\home\user\codebase\toolchain\cppad-build> $LASTEXITCODE
-1073741515
PS C:\msys64\home\user\codebase\toolchain\cppad-build> $env:PATH +=";C:\msys64\home\user\codebase\toolchain\ipopt-install\bin\"
PS C:\msys64\home\user\codebase\toolchain\cppad-build> $env:PATH +=";C:\msys64\home\user\codebase\toolchain\mumps-install\bin\"
PS C:\msys64\home\user\codebase\toolchain\cppad-build> $env:PATH +=";C:\msys64\ucrt64\bin"
PS C:\msys64\home\user\codebase\toolchain\cppad-build> .\example\ipopt_solve\example_ipopt_solve.exe
here
Begin test group example/ipopt_solve
get_started         OK
ode_inverse         OK
retape              OK
memory_leak         OK
All 4 tests passed.
End test group example/ipopt_solve
PS C:\msys64\home\user\codebase\toolchain\cppad-build> $LASTEXITCODE
0

The issue is that powershell just fails silently, but if you inspect the exit code, it fails. There is nothing wrong with the build, this is just down to accurately setting the paths.

Ignore previous comments about needing to use Powershell (pwsh.exe), version 7.5.0. Although, this also works just fine in that too.

Finally, this also works totally fine under MSYS2 terminal once I realised it was the paths that were wrong, moreover, $PATH, not LD_LIBRARY_PATH.

user@comp UCRT64 ~/codebase/toolchain/cppad-build
$ ./example/ipopt_solve/example_ipopt_solve.exe

user@comp UCRT64 ~/codebase/toolchain/cppad-build
$ export PATH=$PATH:/home/user/codebase/toolchain/ipopt-install/bin:/home/user/codebase/toolchain/mumps-install/bin

user@comp UCRT64 ~/codebase/toolchain/cppad-build
$ ./example/ipopt_solve/example_ipopt_solve.exe
here
Begin test group example/ipopt_solve
get_started         OK
ode_inverse         OK
retape              OK
memory_leak         OK
All 4 tests passed.
End test group example/ipopt_solve

There are no issues, tests work fine, in all terminals, but you'll need to update your test scripts (make check) to ensure PATH! is correctly set.

@bradbell
Copy link
Contributor

There is no directory called codebase orr toolchain below my c:\msys64 directory.

@a-jp
Copy link
Author

a-jp commented Feb 21, 2025

These are just commands I typed, you need to point them to your mumps and ipopt bin dirs

@bradbell
Copy link
Contributor

bradbell commented Feb 21, 2025

The get_started.sh script below works for me.
Could you provide instructions for running the get_started.exe it creates in DOS ? in powershell ?

#! /usr/bin/env bash
set -e -u
if [ ! -e cppad.git ]
then
    git clone https://github.com/coin-or/CppAD.git cppad.git
fi
cd cppad.git
#
prefix="$(pwd)/build/prefix"
if [ ! -e build ]
then
    mkdir build
fi
cd build
if [ -e CMakeCache.txt ]
then
   rm CMakeCache.txt
fi
cmake -S .. -B . \
    -G "MSYS Makefiles"  \
    -D CMAKE_CXX_COMPILER=g++ \
    -D CMAKE_C_COMPILER=gcc \
    -D CMAKE_BUILD_TYPE=Debug \
    -D cppad_prefix=$(pwd)/prefix \
    -D cppad_static_lib=False
#
make install
cd ../..
if [ ! -e trash ]
then
    mkdir trash
fi
cd trash
cp ../cppad.git/example/get_started/get_started.cpp get_started.cpp
g++ get_started.cpp \
    -I $prefix/include \
    -L $prefix/lib -lcppad_lib \
    -o get_started.exe
#
PATH+=":$prefix/lib"
PATH+=":/mingw64/bin"
./get_started.exe
echo 'get_started.sh: OK'

@a-jp
Copy link
Author

a-jp commented Feb 21, 2025

when I run it under MSYS2, I get:

$ ./example_get_started.exe
f'(3) computed by CppAD = 142

I don't need a script...I've already provided powershell instructions, and MSYS2 instructions. I don't understand your last post can you be more detailed. Also, did you try what I posted and did it work? The point of my last post was to show it working in two terminals just by making sure path is set properly, I don't understand the point of the script?

@bradbell
Copy link
Contributor

If I execute the following script below in the powershell, I get a message that a certain entry point is missing (see image below):

$env:PATH+=";c:\msys64\home\bradl\cppad.git\build\prefix\lib"
$env:PATH+=";c:\msys64\usr\bin"
$env:PATH+=";c:\msys64\mingw64\bin"

cd trash
.\get_started.exe=

Image

@a-jp
Copy link
Author

a-jp commented Feb 21, 2025

cd c:\msys64\home\bradl\cppad.git\build\prefix\lib

ls

send output

@bradbell
Copy link
Contributor

bradbell commented Feb 21, 2025

PS C:\msys64\home\bradl\cppad.git\build\prefix\lib> ls

    Directory: C:\msys64\home\bradl\cppad.git\build\prefix\lib

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----           2/21/2025  4:51 AM                pkgconfig
-a---           2/21/2025  4:51 AM        1525999 libcppad_lib.dll
-a---           2/21/2025  4:51 AM         387434 libcppad_lib.dll.a

PS C:\msys64\home\bradl\cppad.git\build\prefix\lib>

@a-jp
Copy link
Author

a-jp commented Feb 21, 2025

Sure you've not mixed debug and release builds?

@bradbell
Copy link
Contributor

bradbell commented Feb 21, 2025

That was a good idea, but it turned out to not be the problem. I change CMAKE_BUILD_TYPE back to Release, deleted the old
cppad.git/build/prefix directory and re-ran the script get_started.sh. The program get_started.exe runs in my Msys window, but I cannot get it to run in a DOS or powershell window. Does it run in a DOS or powershell window for you ? If so, can you make a .bat or .ps1 file that has the PATH settings that you need to make it work.

P.S.
It is really not helpful that powershell exits without running the program and without any error message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants