从C站出来:错误:输入(1)中的语法错误

时间:2018-10-11 16:11:43

标签: c cmake swig

我对SWIG非常陌生(事实上,这是我的第一个使用它的“项目”),并且遇到了一个我不太了解的错误。 我一直在尝试像这样一小段C代码使用SWIG:

src / fft.c

#include "fft.h"
void separate(double complex *a, int n)
{
  ...
}

void fft2(double complex *x, int n)
{
  ...
}

src / fft.h

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <complex.h>
#include <math.h>
void separate(double complex *a, int n);
void fft2(double complex *x, int n);

这是我的Swig接口文件:

src / swig / fft.i

%module fft
%{
#include "fft.h"
%}
%include "fft.h"

当我使用CMake作为构建系统时,这里是CMakeLists.txt文件

src / CMakeLists.txt

add_library(
    fft SHARED
    fft.c
)

set_target_properties(fft PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(fft PROPERTIES PUBLIC_HEADER "fft.h")

add_subdirectory(swig)

src / swig / CMakeLists.txt

find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})

add_subdirectory(python)

src / swig / python / CMakeLists.txt

find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_PATH})

set(CMAKE_SWIG_FLAGS "")
set_source_files_properties(../fft.i PROPERTIES CPLUSPLUS ON)
include_directories(../..)

swig_add_library(fft LANGUAGE python SOURCES ../fft.i)
swig_link_libraries(fft ${PROJECT_NAME} ${PYTHON_LIBRARIES})

这是cmake ..目录中makebuild的输出:

make

-- The C compiler identification is AppleClang 10.0.0.10001044
-- The CXX compiler identification is AppleClang 10.0.0.10001044
-- Check for working C compiler: 
/Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: 
/Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: 
/Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: 
/Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found SWIG: /usr/local/bin/swig (found version "4.0.0") 
-- Found PythonLibs:
/usr/local/Frameworks/Python.framework/Versions/3.7/ \
lib/libpython3.7m.dylib (found version "3.7.0") 
-- Configuring done
-- Generating done
-- Build files have been written to: 
/Users/simon/Documents/projects/fft/build

制造

Scanning dependencies of target fft
[ 20%] Building C object src/CMakeFiles/fft.dir/fft.c.o
[ 40%] Linking C shared library libfft.dylib
[ 40%] Built target fft
[ 60%] Swig source
/Users/simon/Documents/projects/fft/src/swig/python/../../fft.h:6: 
Error: Syntax error in input(1).
make[2]: *** [src/swig/python/fftPYTHON_wrap.cxx] Error 1
make[1]: *** [src/swig/python/CMakeFiles/_fft.dir/all] Error 2
make: *** [all] Error 2

如您所见,我在macOS(Mojave)上,C中的共享库可以编译,但SWIG似乎无法与标头中的函数声明相处。我尝试删除了complex(仅使用double个数字),它似乎可以正常工作,所以我猜测是无法找到某种原因的complex.h文件...

任何帮助将不胜感激!

谢谢!

0 个答案:

没有答案