Porting nomacs, using sysinfo.h: Linking the sysinfo object fails

I am in the process of porting the nomacs image viewer to FreeBSD. My Makefile is quite ready, including (obviously) all needed libraries.

However, one of them is the sysinfo.h file (I added the required libsysinfo dependency). For some yet unknown reason the linker fails to use it:

Linking CXX executable nomacs
CMakeFiles/nomacs.dir/src/DkUtils.cpp.o: In function `nmc::DkMemory::getFreeMemory()':
DkUtils.cpp:(.text+0x68): undefined reference to `sysinfo'
CMakeFiles/nomacs.dir/src/DkUtils.cpp.o: In function `nmc::DkMemory::getTotalMemory()':
DkUtils.cpp:(.text+0xc8): undefined reference to `sysinfo'
*** Error code 1

The sysinfo struct is defined in the sysinfo.h file. Do I have to tell the linker to accept it separately?
 
I meanwhile figured the LDFLAGS part out. Now libsysinfo needs another dependency:

Linking CXX executable nomacs
/usr/local/lib/libsysinfo.so: undefined reference to `kvm_getprocs'
/usr/local/lib/libsysinfo.so: undefined reference to `kvm_open'
/usr/local/lib/libsysinfo.so: undefined reference to `kvm_close'
/usr/local/lib/libsysinfo.so: undefined reference to `kvm_getswapinfo'
/usr/local/lib/libsysinfo.so: undefined reference to `kvm_getloadavg'
*** Error code 1

Uhm, what?
 
It's a bug in devel/libsysinfo:
Code:
$ echo 'int main(void) { return 0; }' | cc -xc - -o /dev/null -L/usr/local/lib -lsysinfo
/usr/local/lib/libsysinfo.so: undefined reference to `kvm_getprocs'
/usr/local/lib/libsysinfo.so: undefined reference to `kvm_open'
/usr/local/lib/libsysinfo.so: undefined reference to `kvm_getloadavg'
/usr/local/lib/libsysinfo.so: undefined reference to `kvm_getswapinfo'
/usr/local/lib/libsysinfo.so: undefined reference to `kvm_close'
cc: error: linker command failed with exit code 1 (use -v to see invocation)
In such case you should file a PR with a trivial patch to fix it.
 
Fine. :)

I noticed I can work around it by just defining -lkvm in my makefile; anyway, it seems to be an actual bug indeed. I'll file a PR, thanks!
 
Back
Top