What does the problematic line (and preferebly some context around it) look like?
Tutorial: Making CLAP plugins
- KVRAF
- 7959 posts since 12 Feb, 2006 from Helsinki, Finland
-
- KVRer
- 4 posts since 1 Jul, 2023
AUTO-ADMIN: Non-MP3, WAV, OGG, SoundCloud, YouTube, Vimeo, Twitter and Facebook links in this post have been protected automatically. Once the member reaches 5 posts the links will function as normal.
Code: Select all (#)
static const clap_plugin_descriptor_t pluginDescriptor = {
.clap_version = CLAP_VERSION_INIT,
.id = "nakst.HelloCLAP",
.name = "HelloCLAP",
.vendor = "nakst",
.url = "https://nakst.gitlab.io",
.manual_url = "https://nakst.gitlab.io",
.support_url = "https://nakst.gitlab.io",
.version = "1.0.0",
.description = "The best audio plugin ever.",
.features = (const char *[]) {
CLAP_PLUGIN_FEATURE_INSTRUMENT,
CLAP_PLUGIN_FEATURE_SYNTHESIZER,
CLAP_PLUGIN_FEATURE_STEREO,
NULL,
},
};
- KVRAF
- 7959 posts since 12 Feb, 2006 from Helsinki, Finland
I'm honestly not sure. It could be the construct is only valid in C(?) even though at least clang does seem to accept it as C++ as well... or it could be a GCC/Clang extension or something like that perhaps?Majisto wrote: ↑Sun Jul 02, 2023 11:45 pmIt's in the .features part.Code: Select all
static const clap_plugin_descriptor_t pluginDescriptor = { .clap_version = CLAP_VERSION_INIT, .id = "nakst.HelloCLAP", .name = "HelloCLAP", .vendor = "nakst", .url = "https://nakst.gitlab.io", .manual_url = "https://nakst.gitlab.io", .support_url = "https://nakst.gitlab.io", .version = "1.0.0", .description = "The best audio plugin ever.", .features = (const char *[]) { CLAP_PLUGIN_FEATURE_INSTRUMENT, CLAP_PLUGIN_FEATURE_SYNTHESIZER, CLAP_PLUGIN_FEATURE_STEREO, NULL, }, };
That said, you should be able to fix this by declaring the array of feature strings as a separate static array and reference that. Not as nice syntax-wise, but produces the same end result.
- KVRAF
- 2284 posts since 25 Sep, 2014 from Specific Northwest
It might be an MSVC vs gcc vs clang thing. They've always had these little differences and I've occasionally run into them in the past. It's really annoying and why I don't care for working with other people's code.
I started on Logic 5 with a PowerBook G4 550Mhz. I now have a MacBook Air M1 and it's ~165x faster! So, why is my music not proportionally better?
-
- KVRer
- 1 posts since 22 Oct, 2023
AUTO-ADMIN: Non-MP3, WAV, OGG, SoundCloud, YouTube, Vimeo, Twitter and Facebook links in this post have been protected automatically. Once the member reaches 5 posts the links will function as normal.
It's definitely a MSVC vs GCC/CLANG thing. The code builds perfectly on Linux and Mac but it doesn't on Windows.
A valid approach to fix this (without creating any global stuff) is to create a function for the initialization:
Code: Select all (#)
const char **features_init(); //function prototype
const char **features_init() {
static const char *features[] = {
CLAP_PLUGIN_FEATURE_INSTRUMENT,
CLAP_PLUGIN_FEATURE_SYNTHESIZER,
CLAP_PLUGIN_FEATURE_STEREO,
NULL,
};
return features;
}
static const clap_plugin_descriptor_t pluginDescriptor = {
.clap_version = CLAP_VERSION_INIT,
.id = "nakst.HelloCLAP",
.name = "HelloCLAP",
.vendor = "nakst",
.url = "https://nakst.gitlab.io",
.manual_url = "https://nakst.gitlab.io",
.support_url = "https://nakst.gitlab.io",
.version = "1.0.0",
.description = "The best audio plugin ever.",
.features = features_init()
};
-The correct flag for DLL making on modern versions of the MSVC compiler is /LD, not /DLL.
-The libraries that have to be added to the compiler command line are user32.lib and gdi32.lib (instead of .dll, as stated on the tutorial).
Thus, the correct command to build the example under Windows should be:
Code: Select all (#)
cl /LD /Zi /std:c++20 plugin.cpp user32.lib gdi32.lib
- KVRAF
- 7959 posts since 12 Feb, 2006 from Helsinki, Finland
Constants declared "static" (ie. local to compilation unit) are not what they mean when they say to avoid globals. Function statics are actually theoretically worse, because initialization is on first call and required to be thread-safe.. though here it's all constants so likely to result in the same code either way.Mastropiero wrote: ↑Sun Oct 22, 2023 3:09 pm A valid approach to fix this (without creating any global stuff) is to create a function for the initialization:
Globals in general, even true globals, aren't all bad.. it's just that if you use them for stuff that's not truly supposed to be global, or where you might need multiple copies later, things tend to get messy.