Trouble Linking SNOPT to EMTG

27 views
Skip to first unread message

David Walker

unread,
Dec 9, 2023, 6:37:56 PM12/9/23
to SNOPT
Hello,

I have run into some issues linking SNOPT to EMTG, an orbital simulator in C with a Python wrapper interface. The instructions for linking SNOPT bring me to the SBSI page and follow steps for compiling from source, but I got my license and code from this UCSD site and am attempting to use the already-compiled windows code.

I believe the main issue is that the setup instructions I have have the wrong calls to link the already-compiled SNOPT to EMTG, but I'm not sure how to set up the correct links without the missing source files referenced in the "CMakeLists.txt" file. It seems to check a lot of places, most of which don't exist, including "interfaces" or "cppsrc" folders. It's possible that I don't have all the code from SNOPT that I require for the setup.

I am running on Windows x64. My version of already-compiled SNOPT is in a folder called snopt7 and has only 3 files in it, shown in the picture below.

This is my first time using CMake and SNOPT so any help would be immensely helpful! I believe the solution should be relatively straightforward but I'm hoping someone with more expertise can point me in the right direction.

Best,
David L Walker

======== libsnopt7 root folder ========
Screenshot 2023-12-09 183002.png

======== CMake Error Output ========

Now checking on SNOPT...

CMake Error at CMakeLists.txt:268 (message):
Could not find snopt

Configuring incomplete, errors occurred!


======== CMake Code ========

set(SNOPT_ROOT_DIR C:/Users/David/EMTG/SNOPT/libsnopt7)


#assume newest version of SNOPT
if (IS_DIRECTORY ${SNOPT_ROOT_DIR}/interfaces)
include_directories("${SNOPT_ROOT_DIR}/interfaces/include")

set(SNOPT_INTERFACE_HEADERS ${SNOPT_ROOT_DIR}/interfaces/include/snoptProblem.hpp ${SNOPT_ROOT_DIR}/interfaces/include/snopt.h)
set(SNOPT_INTERFACE_SOURCE ${SNOPT_ROOT_DIR}/interfaces/src/snoptProblem.cpp)
   
    if (MSVC AND SNOPT_MINGW_DLL)
   
        set(SNOPT_LIBRARIES ${SNOPT_ROOT_DIR}/build/${CMAKE_CFG_INTDIR}/libsnopt.lib)
       
        add_library(snopt_interface STATIC IMPORTED)
        set_property(TARGET snopt_interface PROPERTY IMPORTED_LOCATION "${SNOPT_ROOT_DIR}/build/${CMAKE_CFG_INTDIR}/snopt_interface.lib")
        link_directories(${SNOPT_ROOT_DIR}/build/${CMAKE_CFG_INTDIR})
        set(SNOPT_LIBRARIES ${SNOPT_LIBRARIES} snopt_interface)
   
    else()

        #PULL IN SNOPT.  THIS ASSUMES SNOPT HAS ALREADY BEEN COMPILED AND IS IN A VERY SPECIFIC SPOT.
        if (NOT MSVC)
            add_library(snopt SHARED IMPORTED)
            add_library(snopt_cpp SHARED IMPORTED)
            set_property(TARGET snopt PROPERTY IMPORTED_LOCATION "${SNOPT_ROOT_DIR}/lib/.libs/libsnopt7.so")
            set_property(TARGET snopt_cpp PROPERTY IMPORTED_LOCATION "${SNOPT_ROOT_DIR}/lib/.libs/libsnopt7_cpp.so")
        else(NOT MSVC)
            add_library(snopt STATIC IMPORTED)
            set_property(TARGET snopt PROPERTY IMPORTED_LOCATION "${SNOPT_ROOT_DIR}/lib/snopt.lib")
            set(EMTG_LIBRARIES ${EMTG_LIBRARIES} ifmodintr.lib)
            link_directories("${INTEL_FORTRAN_DIR}")
           
        endif(NOT MSVC)
       

        if (MSVC)
            link_directories("${PROJECT_SOURCE_DIR}/lib")
            link_directories(${SNOPT_ROOT_DIR}/lib)
        else()
            link_directories("${PROJECT_SOURCE_DIR}/lib")
            link_directories(${SNOPT_ROOT_DIR}/lib/.libs)
        endif()
        add_library(snopt_interface ${SNOPT_INTERFACE_HEADERS} ${SNOPT_INTERFACE_SOURCE})
        if (MSVC)
            set(SNOPT_LIBRARIES snopt_interface snopt)
        else()
            target_link_libraries(snopt_interface gfortran)
            set(SNOPT_LIBRARIES snopt_interface snopt_cpp snopt)
        endif()
       
        set_property(TARGET snopt_interface PROPERTY POSITION_INDEPENDENT_CODE ON)
       
    endif()


#okay, do we have an older version of SNOPT?

elseif(IS_DIRECTORY ${SNOPT_ROOT_DIR}/cppsrc)
include_directories("${SNOPT_ROOT_DIR}/cppsrc")
include_directories("${SNOPT_ROOT_DIR}/win32")
set(SNOPT_INTERFACE_HEADERS ${SNOPT_ROOT_DIR}/win32/f2c.h ${SNOPT_ROOT_DIR}/cppsrc/snoptProblem.hh ${SNOPT_ROOT_DIR}/cppsrc/snopt.hh ${SNOPT_ROOT_DIR}/cppsrc/snfilewrapper.hh)
set(SNOPT_INTERFACE_SOURCE ${SNOPT_ROOT_DIR}/cppsrc/snfilewrapper.c ${SNOPT_ROOT_DIR}/cppsrc/snoptProblem.cc)

#PULL IN SNOPT.  THIS ASSUMES SNOPT HAS ALREADY BEEN COMPILED AND IS IN A VERY SPECIFIC SPOT.
add_library(f2c STATIC IMPORTED)
add_library(snopt_cpp STATIC IMPORTED)
add_library(snopt_c STATIC IMPORTED)
add_library(snoptsnprint STATIC IMPORTED)

if (NOT MSVC)
set_property(TARGET f2c PROPERTY IMPORTED_LOCATION "${SNOPT_ROOT_DIR}/lib/libf2c.a")
set_property(TARGET snopt_cpp PROPERTY IMPORTED_LOCATION "${SNOPT_ROOT_DIR}/lib/libsnopt_cpp.a")
set_property(TARGET snoptsnprint PROPERTY IMPORTED_LOCATION "${SNOPT_ROOT_DIR}/lib/libsnprint_c.a")
set_property(TARGET snopt_c PROPERTY IMPORTED_LOCATION "${SNOPT_ROOT_DIR}/lib/libsnopt_c.a")
set(SNOPT_LIBRARIES snopt_c snoptsnprint snopt_cpp f2c)
else(NOT MSVC)
set_property(TARGET f2c PROPERTY IMPORTED_LOCATION "${SNOPT_ROOT_DIR}/win32/snopt_csrc/Release/vcf2c.lib")
set_property(TARGET snopt_c PROPERTY IMPORTED_LOCATION "${SNOPT_ROOT_DIR}/win32/snopt_csrc/Release/snopt.lib")
set(SNOPT_LIBRARIES snopt_c f2c)
endif(NOT MSVC)

link_directories("${PROJECT_SOURCE_DIR}/lib")

add_definitions(-DSNOPT72 "Use SNOPT 7.2-12 or older" ON)

else(IS_DIRECTORY ${SNOPT_ROOT_DIR}/interfaces)
message(FATAL_ERROR "Could not find snopt")
endif(IS_DIRECTORY ${SNOPT_ROOT_DIR}/interfaces)

include_directories(${SNOPT_INCLUDE_DIR})

set(EMTG_LIBRARIES ${EMTG_LIBRARIES} ${SNOPT_LIBRARIES})

Reply all
Reply to author
Forward
0 new messages