albertodemichelis / squirrel

Official repository for the programming language Squirrel
http://www.squirrel-lang.org
MIT License
926 stars 161 forks source link

sq_static doesn't build due to undefined C++ symbols #290

Closed ryandesign closed 4 weeks ago

ryandesign commented 3 months ago

Building squirrel 3.2 on macOS using cmake fails:

[ 95%] Linking C executable ../bin/sq_static
cd /opt/local/var/macports/build/_Volumes_Shared_macports-ports_lang_squirrel/squirrel/work/build/sq && /opt/local/bin/cmake -E cmake_link_script CMakeFiles/sq_static.dir/link.txt --verbose=ON
cd /opt/local/var/macports/build/_Volumes_Shared_macports-ports_lang_squirrel/squirrel/work/build/sqstdlib && /opt/local/bin/cmake -E cmake_symlink_library ../lib/libsqstdlib.0.0.0.dylib ../lib/libsqstdlib.0.dylib ../lib/libsqstdlib.dylib
/usr/bin/clang -pipe -Os -DNDEBUG -I/opt/local/include -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -mmacosx-version-min=12.0 -Wl,-search_paths_first -Wl,-headerpad_max_install_names -L/opt/local/lib -Wl,-headerpad_max_install_names -Wl,-syslibroot,/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk CMakeFiles/sq_static.dir/sq.c.o -o ../bin/sq_static  -Wl,-rpath,/opt/local/lib ../lib/libsquirrel_static.a ../lib/libsqstdlib_static.a
make[2]: Leaving directory `/opt/local/var/macports/build/_Volumes_Shared_macports-ports_lang_squirrel/squirrel/work/build'
Undefined symbols for architecture x86_64:
  "std::terminate()", referenced from:
      ___clang_call_terminate in libsquirrel_static.a(sqapi.cpp.o)
      ___clang_call_terminate in libsqstdlib_static.a(sqstdblob.cpp.o)
      ___clang_call_terminate in libsquirrel_static.a(sqobject.cpp.o)
      ___clang_call_terminate in libsquirrel_static.a(sqstate.cpp.o)
      ___clang_call_terminate in libsquirrel_static.a(sqcompiler.cpp.o)
      ___clang_call_terminate in libsquirrel_static.a(sqclass.cpp.o)
      ___clang_call_terminate in libsquirrel_static.a(sqvm.cpp.o)
      ...
  "vtable for __cxxabiv1::__class_type_info", referenced from:
      typeinfo for SQStream in libsqstdlib_static.a(sqstdio.cpp.o)
      typeinfo for SQStream in libsqstdlib_static.a(sqstdblob.cpp.o)
      typeinfo for SQRefCounted in libsquirrel_static.a(sqobject.cpp.o)
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for __cxxabiv1::__si_class_type_info", referenced from:
      typeinfo for SQFile in libsqstdlib_static.a(sqstdio.cpp.o)
      typeinfo for SQBlob in libsqstdlib_static.a(sqstdblob.cpp.o)
      typeinfo for SQString in libsquirrel_static.a(sqobject.cpp.o)
      typeinfo for SQCollectable in libsquirrel_static.a(sqobject.cpp.o)
      typeinfo for SQArray in libsquirrel_static.a(sqobject.cpp.o)
      typeinfo for SQDelegable in libsquirrel_static.a(sqobject.cpp.o)
      typeinfo for SQUserData in libsquirrel_static.a(sqobject.cpp.o)
      ...
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "operator delete(void*)", referenced from:
      SQFile::~SQFile() in libsqstdlib_static.a(sqstdio.cpp.o)
      SQBlob::~SQBlob() in libsqstdlib_static.a(sqstdblob.cpp.o)
      SQClosure::~SQClosure() in libsquirrel_static.a(sqobject.cpp.o)
      SQFunctionProto::~SQFunctionProto() in libsquirrel_static.a(sqobject.cpp.o)
      SQString::~SQString() in libsquirrel_static.a(sqobject.cpp.o)
      SQArray::~SQArray() in libsquirrel_static.a(sqobject.cpp.o)
      SQUserData::~SQUserData() in libsquirrel_static.a(sqobject.cpp.o)
      ...
  "___cxa_begin_catch", referenced from:
      ___clang_call_terminate in libsquirrel_static.a(sqapi.cpp.o)
      ___clang_call_terminate in libsqstdlib_static.a(sqstdblob.cpp.o)
      ___clang_call_terminate in libsquirrel_static.a(sqobject.cpp.o)
      ___clang_call_terminate in libsquirrel_static.a(sqstate.cpp.o)
      ___clang_call_terminate in libsquirrel_static.a(sqcompiler.cpp.o)
      ___clang_call_terminate in libsquirrel_static.a(sqclass.cpp.o)
      ___clang_call_terminate in libsquirrel_static.a(sqvm.cpp.o)
      ...
  "___cxa_pure_virtual", referenced from:
      vtable for SQRefCounted in libsquirrel_static.a(sqobject.cpp.o)
      vtable for SQDelegable in libsquirrel_static.a(sqobject.cpp.o)
  "___gxx_personality_v0", referenced from:
      _sq_newthread in libsquirrel_static.a(sqapi.cpp.o)
      _sq_compile in libsquirrel_static.a(sqapi.cpp.o)
      _sq_pushstring in libsquirrel_static.a(sqapi.cpp.o)
      _sq_pushinteger in libsquirrel_static.a(sqapi.cpp.o)
      _sq_pushbool in libsquirrel_static.a(sqapi.cpp.o)
      _sq_pushfloat in libsquirrel_static.a(sqapi.cpp.o)
      _sq_pushuserpointer in libsquirrel_static.a(sqapi.cpp.o)
      ...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [bin/sq_static] Error 1

This happens because you are trying to link the executable sq_static using the C compiler. It contains objects derived from C++ files so you need to be linking it using the C++ compiler instead so that the C++ standard library will be linked in as well.

You are explicitly requesting to link with the C compiler here:

https://github.com/albertodemichelis/squirrel/blob/c02bf2dfd599a0b99b814d486512a3ee934667f1/sq/CMakeLists.txt#L5

https://github.com/albertodemichelis/squirrel/blob/c02bf2dfd599a0b99b814d486512a3ee934667f1/sq/CMakeLists.txt#L19

Removing the explicit LINKER_LANGUAGE C allows cmake to choose the appropriate linker language for you.