Symbols not found for architecture: trouble compiling with C++

Hello,
I am writing a program which relies on some heavy astronomy calculations, so I am using libnova c++ astronomy libraries => libnova: libnova.
I started off with a simple program to make sure everything compiled ok (below)

//Simple example program to test Libnova C++ class libraries

#include <stdio.h>
#include <libnova/lunar.h>
#include <libnova/julian_day.h>

int main (int argc, char* argv[])
{
    double JD;
    double moonDisk;
    //Get Julian Date from System
    JD = ln_get_julian_from_sys(); //function from julian_day.c
    
    //Use JD to calculate the illuminated lunar disk percentage
    moonDisk = ln_get_lunar_disk(JD); //function from lunar.c
    return 0;
}

But when I try to compile this, using

g++ -o Astro AstroTest.cpp

I receive the following error:

Undefined symbols for architecture x86_64:
  "_ln_get_julian_from_sys", referenced from:
      _main in ccrtNz4O.o
  "_ln_get_lunar_disk", referenced from:
      _main in ccrtNz4O.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

I researched this error and it seems like it is pretty general. I am using a MacbookPro OSX 10.8, and "uname -m" gives me "x86_64". And when I run

file lib/libnova.dylib

I get "Mach-O 64-bit dynamically linked shared library x86_64". I am not sure what the problem is here, any help would be very appreciated.
Thanks

You have to tell g++ to use the library.

g++ -o Astro AstroTest.cpp lib/libnova.dylib
1 Like

That works... Thanks!