Using Cspice with mingw

梦想的初衷 提交于 2020-01-06 07:21:09

问题


I am trying to use cspice with g++ for windows via mingw. Unfortunately cspice does not provide a library for mingw. The libraries are available at https://naif.jpl.nasa.gov/naif/toolkit_C.html. It gives undefined reference errors for the functions defined through cspice. It runs properly in Linux. Can anyone suggest a method to make it work.

I run:

g++ -LK:\Data\cspice\lib -IF:\CPP\Libraries\Boost\boost_1_68_0 -o foo foo.cpp -l:cspice.a -lm

The errors I get are:

undefined reference to 'furnsh_c' and other functions I use from 'SpiceUsr.h'.

Am I not linking the file properly or what is the error.


回答1:


I managed to compile this in windows using MinGW.

I downloaded the code from NASA website for UNIX not WINDOWS.

You need to download a libf2c library, the arith.h (comment this line //#include <config.h>) header and the times.h header.

Then I use the following CMakeLists.txt with MinGW and CMAKE for windows.

mkdir build
cd build
cmake .. -G "MinGW Makefiles"
mingw32-make

Some compilation errors will came out but they are very straightforward to solve.

# CMAKE version and project name
cmake_minimum_required( VERSION 2.8.11 )
project( cspice )

# Add preprocessor directives
SET( GCC_COVERAGE_COMPILE_FLAGS "-c -ansi -m64 -O2 -fPIC -DNON_UNIX_STDIO" )
#SET( GCC_COVERAGE_LINK_FLAGS   "-lf2c -lm" )
#SET( GCC_COVERAGE_LINK_FLAGS   "-lf2c" )

SET(CMAKE_CXX_FLAGS        "${CMAKE_CXX_FLAGS}        ${GCC_COVERAGE_COMPILE_FLAGS}" )
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}" )

# Include directories
include_directories( include
                     libf2c )

file( GLOB f2c_src      "libf2c/*.c" )
file( GLOB f2c_headers  "libf2c/*.h" )

file( GLOB csupport_src     "src/csupport/*.c" )
file( GLOB csupport_headers "src/csupport/*.h" )

file( GLOB brief_src     "src/brief_c/*.c" )
file( GLOB chronos_src   "src/chrnos_c/*.c" )
file( GLOB ckbrief_src   "src/ckbref_c/*.c" )
file( GLOB commnt_src    "src/commnt_c/*.c" )
file( GLOB dskbrief_src  "src/dskbrief_c/*.c" )
file( GLOB dskexp_src    "src/dskexp_c/*.c" )
file( GLOB frmdiff_src   "src/frmdif_c/*.c" )
file( GLOB inspekt_src   "src/inspkt_c/*.c" )
file( GLOB mkdsk_src     "src/mkdsk_c/*.c" )
file( GLOB mkspk_src     "src/mkspk_c/*.c" )
file( GLOB msopck_src    "src/msopck_c/*.c" )
file( GLOB spacit_src    "src/spacit_c/*.c" )
file( GLOB spkdiff_src   "src/spkdif_c/*.c" )
file( GLOB spkmerge_src  "src/spkmrg_c/*.c" )
file( GLOB tobin_src     "src/tobin_c/*.c" )
file( GLOB toxfr_src     "src/toxfr_c/*.c" )
file( GLOB version_src   "src/versn_c/*.c" )

file( GLOB cspice_src     "src/cspice/*.c" )
file( GLOB cspice_headers "include/*.h" )

# Libraries
add_library( f2c ${f2c_src} ${f2c_header} )

add_library( csupport ${csupport_src} ${csupport_header} )

add_library( brief    ${brief_src} )
add_library( chronos  ${chronos_src} )
add_library( ckbrief  ${ckbrief_src} )
add_library( commnt   ${commnt_src} )
add_library( dskbrief ${dskbrief_src} )
add_library( dskexp   ${dskexp_src} )
add_library( frmdiff  ${frmdiff_src} )
add_library( inspekt  ${inspekt_src} )
add_library( mkdsk    ${mkdsk_src} )
add_library( mkspk    ${mkspk_src} )
add_library( msopck   ${msopck_src} )
add_library( spacit   ${spacit_src} )
add_library( spkdiff  ${spkdiff_src} )
add_library( spkmerge ${spkmerge_src} )
add_library( tobin    ${tobin_src} )
add_library( toxfr    ${toxfr_src} )
add_library( version  ${version_src} )

add_library( cspice ${cspice_src} ${cspice_headers} )

# Executable
add_executable( simple src/cook_c/simple.c )
add_executable( states src/cook_c/states.c )
add_executable( subpt  src/cook_c/subpt.c )
add_executable( tictoc src/cook_c/tictoc.c )

# Link the executable and libraries
target_link_libraries ( f2c )

target_link_libraries ( csupport f2c )

target_link_libraries ( brief    f2c )
target_link_libraries ( chronos  f2c )
target_link_libraries ( ckbrief  f2c )
target_link_libraries ( commnt   f2c )
target_link_libraries ( dskbrief f2c )
target_link_libraries ( dskexp   f2c )
target_link_libraries ( frmdiff  f2c )
target_link_libraries ( inspekt  f2c )
target_link_libraries ( mkdsk    f2c )
target_link_libraries ( mkspk    f2c )
target_link_libraries ( msopck   f2c )
target_link_libraries ( spacit   f2c )
target_link_libraries ( spkdiff  f2c )
target_link_libraries ( spkmerge f2c )
target_link_libraries ( tobin    f2c )
target_link_libraries ( toxfr    f2c )
target_link_libraries ( version  f2c )

target_link_libraries ( cspice brief chronos ckbrief commnt dskbrief dskexp frmdiff inspekt mkdsk mkspk msopck spacit spkdiff spkmerge tobin toxfr version )

target_link_libraries ( simple cspice )
target_link_libraries ( states cspice )
target_link_libraries ( subpt  cspice )
target_link_libraries ( tictoc cspice )


来源:https://stackoverflow.com/questions/54388219/using-cspice-with-mingw

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!