Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct linker settings #10

Closed
kalsan opened this issue Jan 2, 2020 · 2 comments
Closed

Correct linker settings #10

kalsan opened this issue Jan 2, 2020 · 2 comments

Comments

@kalsan
Copy link

kalsan commented Jan 2, 2020

After installing, the library, I'm currently using gcc -lnosonos mystuff.cpp in the makefile. However whatever I'm trying to compile, I'm getting linker errors. For instance, here's a minimal example:

#include <noson/sonossystem.h>
#include <noson/sonosplayer.h>
#include <noson/contentdirectory.h>
#include <noson/didlparser.h>
#include <noson/imageservice.h>
#include <noson/filestreamer.h>
#ifdef HAVE_PULSEAUDIO
#include <noson/pulsestreamer.h>
#endif

SONOS::System *gSonos = 0;
SONOS::PlayerPtr gPlayer;
int gDebug = 0;

The error message for this example is:

g++ -o binary -lnoson main.cpp
/usr/bin/ld: /tmp/ccv53Urr.o: in function `SONOS::shared_ptr<SONOS::Player>::reset()':
main.cpp:(.text._ZN5SONOS10shared_ptrINS_6PlayerEE5resetEv[_ZN5SONOS10shared_ptrINS_6PlayerEE5resetEv]+0x26): undefined reference to `SONOS::IntrinsicCounter::Decrement()'
/usr/bin/ld: main.cpp:(.text._ZN5SONOS10shared_ptrINS_6PlayerEE5resetEv[_ZN5SONOS10shared_ptrINS_6PlayerEE5resetEv]+0x6d): undefined reference to `SONOS::IntrinsicCounter::~IntrinsicCounter()'
collect2: error: ld returned 1 exit status

What do I need to feed to my linker in order to be able to write noson code?

@janbar
Copy link
Owner

janbar commented Jan 3, 2020

The links must be after the source.

Build and install noson as shared lib:

mkdir build && cd build
cmake .. -DBUILD_SHARED_LIBS=ON
make
sudo make install

The sample program:

#include <noson/sonossystem.h>
#include <noson/sonosplayer.h>
#include <noson/contentdirectory.h>
#include <noson/didlparser.h>
#include <noson/imageservice.h>
#include <noson/filestreamer.h>
#ifdef HAVE_PULSEAUDIO
#include <noson/pulsestreamer.h>
#endif

SONOS::System *gSonos = 0;
SONOS::PlayerPtr gPlayer;
int gDebug = 0;

void handleEventCB(void* handle)
{
  fprintf(stderr, "#########################\n");
  fprintf(stderr, "### Handling event CB ###\n");
  fprintf(stderr, "#########################\n");
}

int main (int argc, char** argv) {

  gSonos = new SONOS::System(0, handleEventCB);
  if (gSonos->Discover())
  {
    printf("Discovered !!!\n");
  }

  delete gSonos;
  exit(0);
}

Then compile you program: note the link follows the source or object file

g++ -o binary main.cpp -lnoson

If you want to use the static lib:

g++ -o binary main.cpp /usr/local/lib/libnoson.a -lpthread -lz -lssl -lcrypto -lFLAC++ -lFLAC -lpulse-simple -lpulse -lm -lrt
./binary
#########################
### Handling event CB ###
#########################
Discovered !!!
#########################
### Handling event CB ###
#########################

@janbar janbar pinned this issue Jan 3, 2020
@kalsan
Copy link
Author

kalsan commented Jan 3, 2020

Thanks a lot! The static lib worked right away, the shared lib approach after running sudo ldconfig. Thank you very much for your blazing fast and very helpful reply. I'll happily code on.

@kalsan kalsan closed this as completed Jan 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants