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



## Cthulhux (Aug 15, 2012)

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:kMemory::getFreeMemory()':
> DkUtils.cpp.text+0x68): undefined reference to `sysinfo'
> CMakeFiles/nomacs.dir/src/DkUtils.cpp.o: In function `nmc:kMemory::getTotalMemory()':
> ...



The sysinfo struct is defined in the sysinfo.h file. Do I have to tell the linker to accept it separately?


----------



## Cthulhux (Aug 16, 2012)

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'
> ...



Uhm, what?


----------



## oops (Aug 16, 2012)

It's a bug in devel/libsysinfo:
	
	



```
$ 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.


----------



## Cthulhux (Aug 16, 2012)

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!


----------

