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

Do I need to add -lpthread to linker flags? #1193

Closed
eldariont opened this issue Jul 23, 2019 · 2 comments · Fixed by #1200
Closed

Do I need to add -lpthread to linker flags? #1193

eldariont opened this issue Jul 23, 2019 · 2 comments · Fixed by #1200
Labels
question a user question how to do certain things

Comments

@eldariont
Copy link
Collaborator

Platform

Description

How to repeat the problem

I'm writing an application based on seqan3. This is how my project directory looks like:

submodules/seqan3
src/
- CMakeLists.txt
- main.cpp

CMakeLists.txt:

cmake_minimum_required (VERSION 3.4)
project (seqan3_tutorial CXX)
set(SeqAn3_DIR "${CMAKE_SOURCE_DIR}/../submodules/seqan3/build_system")
find_package (SeqAn3 REQUIRED)
add_executable (main main.cpp)
target_link_libraries (main seqan3::seqan3)

main.cpp:

#include <seqan3/argument_parser/all.hpp>   // includes all necessary headers
#include <seqan3/core/debug_stream.hpp>     // our custom output stream
#include <seqan3/std/filesystem>            // use std::filesystem::path
#include <seqan3/io/sequence_file/all.hpp>  // FASTA support
#include <seqan3/io/alignment_file/all.hpp> // SAM/BAM support

using namespace seqan3;

struct cmd_arguments
{
    std::filesystem::path alignment_file_path{};
    std::filesystem::path reference_file_path{};
};

void initialize_argument_parser(argument_parser & parser, cmd_arguments & args)
{
    parser.info.author = "foo";
    parser.info.short_description = "foo";
    parser.info.version = "0.0.1";
    parser.add_positional_option(args.alignment_file_path, "Read alignments in SAM or BAM format.",
                                 input_file_validator{{"sam", "bam"}} );
    parser.add_positional_option(args.reference_file_path, "Reference genome in FASTA format",
                                 input_file_validator{{"fa", "fasta"}} );
}

int main(int argc, char ** argv)
{
    argument_parser myparser{"detectBreakends", argc, argv};        // initialise myparser
    cmd_arguments args{};
    initialize_argument_parser(myparser, args);
    try
    {
        myparser.parse();                                          // trigger command line parsing
    }
    catch (parser_invalid_argument const & ext)                     // catch user errors
    {
        debug_stream << "[Error] " << ext.what() << "\n"; // customise your error message
        return -1;
    }
    // run_program(args.alignment_file_path, args.reference_file_path);
    return 0;
}

Expected behaviour

I would expect the program to compile successfully with:

mkdir build
cd build
cmake ../src
make

Actual behaviour

>make
Scanning dependencies of target main
[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
[100%] Linking CXX executable main
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: CMakeFiles/main.dir/main.cpp.o: undefined reference to symbol 'pthread_create@@GLIBC_2.2.5'
/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /lib/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/main.dir/build.make:86: main] Error 1
make[1]: *** [CMakeFiles/Makefile2:73: CMakeFiles/main.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

I found that add -lpthread to the linker flags solves this issue. But I wondered why it is necessary to do this manually if I only use the seqan argument parser and not much more. Any idea?

Cheers
David

@eldariont eldariont added bug faulty or wrong behaviour of code question a user question how to do certain things and removed bug faulty or wrong behaviour of code labels Jul 23, 2019
@h-2 h-2 closed this as completed in #1200 Aug 3, 2019
@h-2
Copy link
Member

h-2 commented Aug 3, 2019

Can you verify that the latest master branch fixes the problem?

@eldariont
Copy link
Collaborator Author

Yes, the latest master branch fixes the problem. Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question a user question how to do certain things
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants