Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • nickhill
    Member
    • Oct 2015
    • 11

    Trouble Using BamTools

    Hi everyone,

    I have successfully downloaded BamTools but am still having trouble incorporating it into my code. When I compile with make, I get the errors like:

    main.cpp:7:10: fatal error: 'api/BamMultiReader.h' file not found
    #include "api/BamMultiReader.h"

    It seems like the download is not working but I am quite sure it worked. If I ls into my bamtools folder I see:

    CMakeLists.txt README build include src
    LICENSE bin docs lib

    The api folder with its contents is located in include. It seems like I have the necessary libraries. Is there something I need to include in my Makefile to be able use the bamtools libraries in my code?
  • blancha
    Senior Member
    • May 2013
    • 367

    #2
    It's possible that you are not including the path to the header files when compiling.

    First, you can check that you indeed have the header files.
    Code:
    blancha@hai04 ~/Desktop$ ls /Applications/bamtools/include/api/
    BamAlgorithms.h           BamIndex.h                IBamIODevice.h            SamProgramChain.h         SamSequenceDictionary.h
    BamAlignment.h            BamMultiReader.h          SamConstants.h            SamReadGroup.h            algorithms/
    BamAux.h                  BamReader.h               SamHeader.h               SamReadGroupDictionary.h  api_global.h
    BamConstants.h            BamWriter.h               SamProgram.h              SamSequence.h
    Then, you just need to include the path to the header file when compiling.
    Code:
    g++ test.cpp -I /Applications/bamtools/include/ -L /Applications/bamtools/lib/ -lbamtools
    I know that you asked for a Makefile, so I'll try and write the equivalent command later using a Make file.
    As you can see, I'm not a C++ programmer, so someone else on the forum will probably explain to you better than me that you need to include the path to the header files when compiling, but I'm answering the question since no one has tried yet.

    If I put the wrong path to the header file or don't include the path at all, I get the same error message as you, leading me to believe this could be the bug.

    Comment

    • blancha
      Senior Member
      • May 2013
      • 367

      #3
      Ok, here is my MakeFile to compile the program in the Bamtools API tutorial.

      Code:
      CC=g++
      IDIR=/Applications/bamtools/include/
      LDIR=/Applications/bamtools/lib/
      CFLAGS=-I $(IDIR)
      LFLAGS=-L $(LDIR) -lbamtools
      
      test: test.cpp
              $(CC) $(CFLAGS) $(LFLAGS) test.cpp
      It's my first time writing a Makefile, so I hope it's not a case of the blind leading the blind.

      I do believe your bug is simply that you are not including the path to the header files when compiling, assuming that the header files are indeed in the include bamtools subfolder.

      Comment

      • blancha
        Senior Member
        • May 2013
        • 367

        #4
        This site has a nice explanation for all the possible causes and solutions to your bug.

        Introduction In this intermittent series, I’ll be looking at the most common error messages your C++ compiler (and linker) can produce, explaining exactly what they mean, and showing how they…


        What program are your trying to write?

        Comment

        • nickhill
          Member
          • Oct 2015
          • 11

          #5
          I included the path and still receive errors about using BamTools

          error: expected namespace name
          using namespace BamTools;
          ^
          Here is my Makefile:

          CC = g++ -g -O0 -Wall -Wextra -std=gnu++11
          IDIR = /Users/nicholashill/src/new/bamtools/include/
          LDIR = /Users/nicholashill/src/new/bamtools/lib/
          CFLAGS=-I $(IDIR)
          LFLAGS=-L $(LDIR) -lbamtools
          SOURCES = main.cpp new.cpp

          CPPHEADER = new.h
          OBJECTS = $(SOURCES:.cpp=.o)

          EXECUTABLE = new

          main: main.cpp
          $(CC) $(CFLAGS) $(LFLAGS) main.cpp

          all: $(SOURCES) $(EXECUTABLE)

          $(EXECUTABLE): $(OBJECTS)
          $(CC) $(OBJECTS) -o $@

          .cpp.o:
          $(CC) $(CXXFLAGS) $< -o $@

          clean:
          - rm $(OBJECTS)

          spotless:
          - rm ${EXECUTABLE}

          Comment

          • nickhill
            Member
            • Oct 2015
            • 11

            #6
            I am trying to a write a program which requires taking BAM as an input file

            Comment

            • nickhill
              Member
              • Oct 2015
              • 11

              #7
              I cannot execute the bamtools executable in the bamtools/bin. Could this be the problem?

              Comment

              • GenoMax
                Senior Member
                • Feb 2008
                • 7142

                #8
                Add execute permissions to the file (you are on a Mac?)

                Code:
                $ sudo chmod a+x /path_to/bamtools

                Comment

                • nickhill
                  Member
                  • Oct 2015
                  • 11

                  #9
                  Thanks yes I got the executable working but I am still unable to include bam tools for developing code

                  Comment

                  • GenoMax
                    Senior Member
                    • Feb 2008
                    • 7142

                    #10
                    What exactly are you trying to do? Use bamtools code in your own code/extend that code or are you just interested in calling the bamtools binary from your own program?

                    Comment

                    • nickhill
                      Member
                      • Oct 2015
                      • 11

                      #11
                      Just use bamtools in my own code. I've just been confused about whether I have bamtools since the compiler doesn't recognize when I incorporate it in my code

                      Comment

                      • GenoMax
                        Senior Member
                        • Feb 2008
                        • 7142

                        #12
                        Have you looked at the wiki: https://github.com/pezmaster31/bamtools/wiki?

                        Comment

                        • nickhill
                          Member
                          • Oct 2015
                          • 11

                          #13
                          Yeah i've been looking at the API tutorial for help which is why i've been trying to edit my Makefile to include the library and include paths but have been unsuccessful. I apologize for my ignorance, this is the first time i've tried to use outside developers libraries in my own code.

                          Comment

                          • blancha
                            Senior Member
                            • May 2013
                            • 367

                            #14
                            You'll get that error message if you don't include the BamTools header file before using the namespace.
                            If I delete the first two lines in my test file that include the BamTools header, I can reproduce your error message.
                            I can't troubleshoot more, without seeing the first few lines of your source code, but that is the bug.

                            These are really basic C++ programming questions, rather than questions specific to BamTools.
                            You might find better answers, and more expertise in a C++ programming forum.
                            That being said, I'm happy to try and answer the questions to the best of my ability, and there are some top-notch C++ programmers on this forum.

                            Also, as you must have realized, there is an h missing in the first line of the example given in the BamTools manual, and the quotes are also incorrect if you just copy-paste the code.

                            Comment

                            • blancha
                              Senior Member
                              • May 2013
                              • 367

                              #15
                              Here is an example illustrating how this error will appear if you don't include the BamTools header in the source code, before using the namespace.

                              I just compile the original code first, without any problems.
                              After I delete the first two lines, which include the BamTools header files, I get the same error message you reported.
                              I use head to show the first few lines of my source code, and sed to delete the first two lines.
                              Code:
                              MacBook-Pro:Downloads blancha$ head test.cpp
                              #include "api/BamMultiReader.h"
                              #include "api/BamWriter.h"
                              using namespace BamTools;
                              using namespace std;
                              
                              int main() {
                              // at some point, start our merge operation
                              vector<string> inputFilenames;
                              string outputFilename;
                              // provide some input & output filenames
                              MacBook-Pro:Downloads blancha$ make
                              g++ -I ~/Downloads/bamtools/include/ -L ~/Downloads/bamtools/lib/ -lbamtools test.cpp
                              MacBook-Pro:Downloads blancha$ sed -i.bak '1,2d' test.cpp
                              MacBook-Pro:Downloads blancha$ head test.cpp
                              using namespace BamTools;
                              using namespace std;
                              
                              int main() {
                              // at some point, start our merge operation
                              vector<string> inputFilenames;
                              string outputFilename;
                              // provide some input & output filenames
                              // attempt to open our BamMultiReader
                              BamMultiReader reader;
                              MacBook-Pro:Downloads blancha$ make
                              g++ -I ~/Downloads/bamtools/include/ -L ~/Downloads/bamtools/lib/ -lbamtools test.cpp
                              test.cpp:1:17: error: expected namespace name
                              using namespace BamTools;
                              Last edited by blancha; 10-30-2015, 03:55 PM.

                              Comment

                              Latest Articles

                              Collapse

                              ad_right_rmr

                              Collapse

                              News

                              Collapse

                              Topics Statistics Last Post
                              Started by SEQadmin2, Today, 10:09 AM
                              0 responses
                              9 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, Yesterday, 08:59 AM
                              0 responses
                              16 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 06-02-2026, 12:03 PM
                              0 responses
                              24 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 06-02-2026, 11:40 AM
                              0 responses
                              21 views
                              0 reactions
                              Last Post SEQadmin2  
                              Working...