docb / dbRackCsound

GNU General Public License v3.0
15 stars 2 forks source link

Build failure with Rack Plugin Toolchain #1

Closed cschol closed 1 year ago

cschol commented 1 year ago

Moving this discussion to your plugin issue tracker.

First, your plugin does not build with the official rack-plugin-toolchain.

There is no need to include arch.mk. It is already available and include by Rack automatically. This code will break when compiled with the Rack Plugin Toolchain.

diff --git a/Makefile b/Makefile
index 45b0398..d2cf2fc 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,6 @@ CXXFLAGS +=

 # Careful about linking to shared libraries, since you can't assume much about the user's environment and library search path.
 # Static libraries are fine, but they should be added to this plugin's build system.
-include ../../arch.mk
 ifdef ARCH_MAC
   FLAGS += -I lib/mac/CsoundLib64.framework/Versions/6.0/Headers
   #link and deliver csound framework on mac

Second, the Windows cross-compile fails due to a linker error:

x86_64-w64-mingw32-g++ -o plugin.dll build/src/CsoundModule.cpp.o build/src/plugin.cpp.o build/src/rnd.cpp.o build/src/textfield.cpp.o lib/linux/libcsound64.a lib/linux/libcsnd6.a -shared -L/home/build/rack-plugin-toolchain/Rack-SDK-win -lRack -static-libstdc++ 
/home/build/rack-plugin-toolchain/local/x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld: build/src/CsoundModule.cpp.o: in function `Csound::SystemSr(double)':
/home/build/plugin-src/lib/linux/csound/csound.hpp:935: undefined reference to `csoundSystemSr'
/home/build/rack-plugin-toolchain/local/x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld: build/src/CsoundModule.cpp.o: in function `Csound::SetAudioChannel(char const*, double*)':
/home/build/plugin-src/lib/linux/csound/csound.hpp:932: undefined reference to `csoundSetAudioChannel'

<snip; too many errors>

/home/build/plugin-src/lib/linux/csound/csound.hpp:192: undefined reference to `csoundCompileOrc'
/home/build/rack-plugin-toolchain/local/x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld: build/src/CsoundModule.cpp.o: in function `Csound::GetNchnls()':
/home/build/plugin-src/lib/linux/csound/csound.hpp:401: undefined reference to `csoundGetNchnls'
/home/build/rack-plugin-toolchain/local/x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld: build/src/CsoundModule.cpp.o: in function `Csound::GetKsmps()':
/home/build/plugin-src/lib/linux/csound/csound.hpp:397: undefined reference to `csoundGetKsmps'
/home/build/rack-plugin-toolchain/local/x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld: build/src/CsoundModule.cpp.o: in function `Csound::Csound()':
/home/build/plugin-src/lib/linux/csound/csound.hpp:840: undefined reference to `csoundCreate'
/home/build/rack-plugin-toolchain/local/x86_64-w64-mingw32/lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld: /home/build/plugin-src/lib/linux/csound/csound.hpp:840: undefined reference to `csoundCreate'
collect2: error: ld returned 1 exit status

This needs to be resolved before troubleshooting any toolchain build issues. Thanks.

docb commented 1 year ago

@cschol , hi thanks for verifying, may be i have an old version, but this is my output of the toolchain: (Please NOTE that your windows build is using the linux variant not the windows as it has these entries: lib/linux/libcsound64.a lib/linux/libcsnd6.a)

[...]
x86_64-w64-mingw32-g++ -o plugin.dll build/src/CsoundModule.cpp.o build/src/plugin.cpp.o build/src/textfield.cpp.o build/src/rnd.cpp.o lib/win/libcsound64.a lib/win/libsndfile.a -lws2_32 -shared -L/home/docb/git/rack-plugin-toolchain/Rack-SDK-win -lRack -static-libstdc++ 
rm -rf dist
mkdir -p dist/dbRackCsound
cp plugin.dll dist/dbRackCsound/
x86_64-w64-mingw32-strip -s dist/dbRackCsound/plugin.dll
cp -r --parents res LICENSE presets plugin.json dist/dbRackCsound/
cd dist && tar -c dbRackCsound | zstd -19 -o "dbRackCsound"-"2.0.0"-win.vcvplugin
/*stdin*\            : 30.86%   (4894720 => 1510620 bytes, dbRackCsound-2.0.0-win.vcvplugin) 
make[1]: Leaving directory '/home/docb/git/Rack2/plugins/dbRackCsound'
mkdir -p plugin-build
cp /home/docb/git/Rack2/plugins/dbRackCsound/dist/*.vcvplugin plugin-build/
cd /home/docb/git/Rack2/plugins/dbRackCsound && make clean
make[1]: Entering directory '/home/docb/git/Rack2/plugins/dbRackCsound'
rm -rfv build plugin.dll dist
removed 'build/src/plugin.cpp.d'
removed 'build/src/rnd.cpp.o'
[...]

no error

commenting out include ../../arch.mk will result in that always the linux variant is taken and this makes the build failing. what should be the solution?

docb commented 1 year ago

And i really do not understand: One latest module Visualizer from RPJ has exacctly the same:

# If RACK_DIR is not defined when calling the Makefile, default to two directories above
$(info Rackdir is $(RACK_DIR))
RACK_DIR ?= ../..

include $(RACK_DIR)/arch.mk

# FLAGS will be passed to both the C and C++ compiler
cschol commented 1 year ago
RACK_DIR ?= ../..

include $(RACK_DIR)/arch.mk

is not the same as

include ../../arch.mk

The toolchain overrides RACK_DIR to be different than ../...

I am looking into while the build process is failing to select the correct arch.

cschol commented 1 year ago

Using

RACK_DIR ?= ../..

include $(RACK_DIR)/arch.mk

fixes the build issues.

This doesn't quite make sense since it should not be necessary to include arch.mk specifically. But I will look at that separately.

I will test the cross-compiled build a Windows system and see if the init() error shows up.

cschol commented 1 year ago

Are you intentionally using the Linux headers for the Windows build?

else ifdef ARCH_WIN
    FLAGS += -I lib/linux/csound
    LDFLAGS +=  lib/win/libcsound64.a lib/win/libsndfile.a -lws2_32
else
docb commented 1 year ago

Yes currently ... because the headers from the windows distribution fail to built - it seems they are not suited for mingw -- i will remove them.

cschol commented 1 year ago

Maybe that is the problem with the missing init() symbol: a mismatch in library and header files.

docb commented 1 year ago

The error message displayed is from the plugin.cpp code and stated that the plugin InitCallback is not found which has imho nothing to do with csound. but one never knows. The referenced headers in the linux dir are cross plattform.

cschol commented 1 year ago

This is the error message from your initial report:

Failed to read init() symbol in C:/Users/User/Documents/Rack2/plugins/dbRackCsound/plugin.dll

Where does the InitCallback message show up?

docb commented 1 year ago

it seems to be obvious that the error message comes from here https://github.com/VCVRack/Rack/blob/5551617afff182925940908eaf73a7d7361303cc/src/plugin.cpp#L114

docb commented 1 year ago

and the init symbol should refer to the init function in the plugin.cpp. https://github.com/docb/dbRackCsound/blob/a0138988d0ac4fe11b131918198703c59d0ba04e/src/plugin.cpp#L10

cschol commented 1 year ago

I looked into this.

I used Dependency Walker to check out the plugin.dll on Windows and it does not contain any Rack related symbols, and definitely not the init symbol. I cross-compiled another plugin and it had the correct Rack symbols, incl. init, present in Dependency Walker. It looks like the symbols in the plugin.dll are only csound related symbols.

I stripped all csound references from your plugin and re-compiled. The Rack symbols now show up correctly. As soon as I add one reference to a csound symbol, for example the line DBCsound cs;, which cause csound to get linked in, the Rack symbols disappear from the plugin.dll.

  1. I would look into the csound build issues for Windows that you talked about above. Where did you get the Windows-specific libraries from? Did you build them yourself?
  2. I would create a very small test project and link in csound to get the link issues figured out. You can also use objdump -p plugin.dll to check on GNU/Linux, which symbols are present in the .dll if you don't have access to Dependency Walker.
docb commented 1 year ago

ok thank you very much! i will look into this.

docb commented 1 year ago

RTFM: mingw ld has the logic to require the option --export-all-symbols IF somewhere there is a __declspec(dllexport) attribute otherwise it exports only these.

cschol commented 1 year ago

Nice find! I tested with a toolchain build and subsequent load on Windows and it works fine now.