c++ 使用emscripten不工作构建可靠示例

2ic8powd  于 2023-01-22  发布在  其他
关注(0)|答案(1)|浏览(161)

我正尝试用emscripten把我的一个项目移植到web上,我在其中使用的一个库是soloud,构建库本身编译得很好,没有错误,但是当我尝试用它编译一个例子时,我得到了一堆编译器错误。
下面是我构建库所使用的步骤:
1.下载并构建genie
1.下载soloud并将genie可执行文件放入构建文件夹
1.运行./genie --with-miniaudio-only gmake
1.将cd复制到gmake目录并运行emmake make
这可以很好地编译,没有任何错误,但是当我尝试使用emcc main.cpp libsoloud_static.a -I ../include -o index.html构建simplest示例时,我得到了这些错误

emcc: warning: libsoloud_static.a: archive is missing an index; Use emar when creating libraries to ensure an index is created [-Wemcc]
emcc: warning: libsoloud_static.a: adding index [-Wemcc]
error: undefined symbol: _ZN6SoLoud6Soloud19getActiveVoiceCountEv (referenced by top-level compiled C/C++ code)
warning: Link with `-sLLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-sERROR_ON_UNDEFINED_SYMBOLS=0`
warning: __ZN6SoLoud6Soloud19getActiveVoiceCountEv may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN6SoLoud6Soloud4initEjjjjj (referenced by top-level compiled C/C++ code)
warning: __ZN6SoLoud6Soloud4initEjjjjj may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN6SoLoud6Soloud4playERNS_11AudioSourceEffbj (referenced by top-level compiled C/C++ code)
warning: __ZN6SoLoud6Soloud4playERNS_11AudioSourceEffbj may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN6SoLoud6Soloud6deinitEv (referenced by top-level compiled C/C++ code)
warning: __ZN6SoLoud6Soloud6deinitEv may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN6SoLoud6SoloudC1Ev (referenced by top-level compiled C/C++ code)
warning: __ZN6SoLoud6SoloudC1Ev may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN6SoLoud6SoloudD1Ev (referenced by top-level compiled C/C++ code)
warning: __ZN6SoLoud6SoloudD1Ev may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN6SoLoud6Speech7setTextEPKc (referenced by top-level compiled C/C++ code)
warning: __ZN6SoLoud6Speech7setTextEPKc may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN6SoLoud6SpeechC1Ev (referenced by top-level compiled C/C++ code)
warning: __ZN6SoLoud6SpeechC1Ev may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN6SoLoud6SpeechD1Ev (referenced by top-level compiled C/C++ code)
warning: __ZN6SoLoud6SpeechD1Ev may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _ZN6SoLoud6Thread5sleepEi (referenced by top-level compiled C/C++ code)
warning: __ZN6SoLoud6Thread5sleepEi may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors

我哪里做错了?

zwghvu4y

zwghvu4y1#

更新:
我可以通过改变这个来让它工作

CC  = gcc
CXX = g++
AR  = ar

到这个

CC  = emcc
CXX = em++
AR  = emar

还有这个

ALL_CPPFLAGS       += $(CPPFLAGS) -MMD -MP -MP $(DEFINES) $(INCLUDES)
  ALL_ASMFLAGS       += $(ASMFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -g -msse4.1 -fPIC
  ALL_CFLAGS         += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -g -msse4.1 -fPIC
  ALL_CXXFLAGS       += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -g -fno-exceptions -fno-rtti -msse4.1 -fPIC
  ALL_OBJCFLAGS      += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -g -msse4.1 -fPIC
  ALL_OBJCPPFLAGS    += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -g -fno-exceptions -fno-rtti -msse4.1 -fPIC

到这个

ALL_CPPFLAGS       += $(CPPFLAGS) -MMD -MP -MP $(DEFINES) $(INCLUDES)
  ALL_ASMFLAGS       += $(ASMFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -g -fPIC
  ALL_CFLAGS         += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -g -fPIC
  ALL_CXXFLAGS       += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -g -fno-exceptions -fno-rtti -fPIC
  ALL_OBJCFLAGS      += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -g -fPIC
  ALL_OBJCPPFLAGS    += $(CXXFLAGS) $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -g -fno-exceptions -fno-rtti -fPIC

(仍然不确定为什么我必须删除-msse4.1标志,但我得到了一个奇怪的错误)
由于某种原因,它仍然使用常规编译器而不是emscripten。

相关问题