GNOME Bugzilla – Bug 599770
Math.sqrt is not proper referenced
Last modified: 2018-05-22 13:24:56 UTC
When trying to use GLib.Math.sqrt with a variable it results in an incorrect referenced C-code. e.g. this simple code: static void main() { double i = 5; stdout.printf("%f\n", Math.sqrt(i)); } will result in an gcc error, where as: static void main() { stdout.printf("%f\n", Math.sqrt(5)); } would work out just fine. The complete error code: /tmp/ccCpbHwm.o: In function `_main': sqrt.vala.c:(.text+0x52): undefined reference to `sqrt' collect2: ld returned 1 exit status error: cc exited with status 256 valac --version: 0.7.7 OS: Debian testing/unstable
It seems like the libm is not included when compiling. Using: valac -C sqrt.vala && gcc `pkg-config --libs --cflags gobject-2.0` -lm sqrt.c works just fine.
Confirming. We will need an attribute to support specifying extra libraries to link with. You can use -X -lm for now.
Moreover, such a facility needs to be platform-dependent, since e.g. on macOS the provided testcase compiles just fine without libm.
I think that's something the build system could handle; Meson already supports optional dependencies and will/won't link as needed/found. This is needed pretty often when using C or C++, and yes, mostly for libm.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/53.