victorliu / S4

Stanford Stratified Structure Solver - Electromagnetic simulator for layered periodic structures
http://www.stanford.edu/group/fan/S4/
GNU General Public License v2.0
133 stars 151 forks source link

Why are some functions declared but not defined? #120

Open jinfreelancing opened 1 month ago

jinfreelancing commented 1 month ago

May be a stupid question, but I'm trying to compile this package and link under Msys2 MinGW toolset under windows 11, including mingw gcc, g++, ld, etc., and python 3.11 with setuptools installed. I managed to get to the point where I have built the libS4.a static library, but upon building the python extension by python setup.py build, I get a long list of linker errors of undefined reference to XXX:

...
writing build/temp.mingw_x86_64-cpython-311/s4/S4.cp311-mingw_x86_64.def
gcc -shared -Wl,--enable-auto-image-base -pipe -pipe -s build/temp.mingw_x86_64-cpython-311/s4/main_python.o build/temp.mingw_x86_64-cpython-311/s4/S4.cp311-mingw_x86_64.def -Lbuild -LE:/msys64/mingw64/lib -lS4 -lstdc++ -lpython3.11 -o build/lib.mingw_x86_64-cpython-311/S4.cp311-mingw_x86_64.pyd
E:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: build/temp.mingw_x86_64-cpython-311/s4/main_python.o: in function `S4Sim_AddLayerCopy':
E:/optics/scratch/rcwa/S4/S4/main_python.c:755:(.text+0x18ba): undefined reference to `Simulation_AddLayer'
E:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/optics/scratch/rcwa/S4/S4/main_python.c:760:(.text+0x18df): undefined reference to `Layer_Init'
E:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: build/temp.mingw_x86_64-cpython-311/s4/main_python.o: in function `S4Sim_AddLayer':
E:/optics/scratch/rcwa/S4/S4/main_python.c:716:(.text+0x198a): undefined reference to `Simulation_AddLayer'
E:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: E:/optics/scratch/rcwa/S4/S4/main_python.c:721:(.text+0x19b0): undefined reference to `Layer_Init'
...

As I searched through source code, I can find declarations for Simulation_AddLayer, Layer_Init, but cannot find their definitions? I am totally confused. I am new to C/C++ coding, please enlighten me. Thanks,

phoebe-p commented 1 month ago

I have tried many times and have never successfully compiled S4 on Windows (it should definitely be possible - I think this is how the original developers did it - but I've never managed it or found instructions).

In any case, this version of S4 does not work with Python 3. There are several forks which do work with newer Python versions, including mine, where I also have installation instructions in the Readme. I recommend either installing Ubuntu/other Linux in a partition on your computer, or running Windows Subsystem for Linux (WSL), which works with for example VSCode.