Search code examples
c++compiler-errorscompilationg++pkg-config

Fail to compile source with JACK API


For reference: i am currently on Manjaro (Arch Linux) and am using the GNU g++ compiler. I want to create a program for JACK (Jack Audio Connection Kit) and am now trying to use their API provided here. I have Jack2 installed, but also tried it with Jack2-dbus. I found something in the AUR called jackcpp, but that didn't help neither.

To get to my problem: I fail to compile their example clients listed, and obviously I fail to build my own using that API. I suspect it is broken, but I can't imagine noone reporting it so I don't really know what to do now.

In my jacktest.cpp the following is written:

#include <iostream>
#include "jack/control.h"

int main(){
    jackctl_server_t *server;
    jackctl_driver_t *driver;

    if (jackctl_server_start(server, driver)) {
        std::cout << "Started!";
        return 0;
    }else{
        std::cout <<"Failed!";
        return 1;
    };
}

based on the function documented here. Try to start a jack server and return a bool if operation successful or not. If I try to compile this (with 'pkg-config' as I am supposed to):

$ g++ -o jacktest `pkg-config --cflags --libs jack` jacktest.cpp

it throws:

jacktest.cpp:8:44: error: too many arguments to function 'bool jackctl_server_start(jackctl_server_t*)'
     if (jackctl_server_start(server, driver))

So I checked and indeed, in my /usr/include/jack/control.h, it defines jackctl_server_start with only one argument. I don't know if their documentation is outdated or if I am missing files/have the wrong ones... Then I tried to do it with only one argument

...    
if (jackctl_server_start(server)) {
...

which then throws:

/usr/bin/ld: /tmp/ccxm3fWC.o: undefined reference to symbol '_ZNSt8ios_base4InitD1Ev@@GLIBCXX_3.4'
/usr/lib/libstdc++.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

I tried to rearrange the arguments:

$ g++ -o jacktest `pkg-config --cflags --libs jack` jacktest.cpp
$ g++ -o jacktest jacktest.cpp `pkg-config --cflags --libs jack`
$ g++ jacktest.cpp `pkg-config --cflags --libs jack` -o jacktest
$ g++  jacktest.cpp -o jacktest `pkg-config --cflags --libs jack`

which always throws the same error...

now the thing that really makes me think something is broken: another jacktest_2.cpp now including jack.h and excluding control.h

#include <iostream>
#include "jack/jack.h"

int main(){
    jack_client_t *client;

    if (client = jack_client_new("test_client")) {
        std::cout << "Running!";
        return 0;
    }else{
        std::cout <<"Not Running!";
        return 1;
    };
}

which I CAN compile:

$ g++ -o jacktest_2 jacktest_2.cpp `pkg-config --cflags --libs jack`

altough it gives me complains that this function is depricated, the program does what it should too! So at least some of it is working?!

Also:

$ g++ -print-file-name=jack 
/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.1/../../../../lib/jack

is that normal? There is no lib/jack in usr/lib/gcc/x86_64-pc-linux-gnu/7.2.1

To conclude: I really NEED control.h, I even went as far as changing control.h and include their 'driver' part from the API Docs back into the function, but that didn't get me anywhere neither... (undefined reference...) I feel like I am missing something really simple, or something really is broken with that API. I have been on this for almost a week, and I just can't figure it out.


Solution

  • If anyone stumbles upon this and wondered what happend: I posted this in the JackAudio forum here. Anyone can read it if he/she wants to, but I will mark this question as answered now, since it really is not a C++ or compiling problem but rather a Jack problem. Thank you!