使用Cspice使用MinGW(Using Cspice with mingw)

2019-10-30 02:15发布

我试图用cspice使用g ++用于通过MinGW的窗口。 不幸的是cspice不提供MinGW的库。 该库可在https://naif.jpl.nasa.gov/naif/toolkit_C.html 。 它提供了通过cspice定义的函数未定义引用错误。 它正常运行在Linux中。 任何人都可以提出,使其工作的方法。

我运行:

克++ -LK:\数据\ cspice \ lib中-IF:\ CPP \库\升压\ boost_1_68_0 -o FOO Foo.cpp中-l:cspice.a -lm

我得到的错误是:

未定义的引用“furnsh_c”和我从“SpiceUsr.h”使用其他功能。

我不是正确链接的文件或什么错误。

Answer 1:

我设法使用MinGW的窗口编译此。

我从网上下载的代码NASA网站对UNIX不是Windows。

你需要下载一个libf2c库中, arith.h (注释此行//#include <config.h> )头和times.h头。

然后我用MinGW和C进行以下的CMakeLists.txt的窗口。

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

一些编译错误会就出来了,但他们是非常简单的解决。

# 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 )


文章来源: Using Cspice with mingw