Using a Library

If we wanted to use the Modern C++ threading library <thread>, e.g.

#include "message.h"

#include <thread> 

#ifdef COUNT
#define COUNT 10
#endif

void run()
{
    for(int i = 0; i < COUNT; ++i){    
        print_message("Hello world");
    }  
}

int main()
{
    std::thread t1 { run };
    t1.join();
    return 0;
}

Then (on a Linux/Unix platform) the library pthread needs adding using the -l option. We can use the LIBS variable, e.g.

env.Append( LIBS = ['pthread'] )

On build this will now generate the linker directive:

g++ -o hello -Wl,-Map,hello.map src/main.o support/message.o -lpthread

Note: It is not considered good practice to use the linker options, e.g.

env.Append(LINKFLAGS = ['-lpthread'])

to set library flags.

results matching ""

    No results matching ""