Compiling Samtools Bam_Plcmd.C For Mpileup Function Invalid Conversion Errors
1
0
Entering edit mode
11.5 years ago
coryprzy • 0

I was looking to use the mpileup function in some c code, so I started with taking bam_plcmd.c, changing the bam_mpileup to main and compiling. This gave me the following conversion errors. At least some of the errors are errors the g++ compiler should catch, but it's also clear the program can compile when using the Makefile to build the whole samtools package.

Is there a way to compile this file directly that doesn't involve hacking it up? Also, how do I / what files do I need to link in to the compiler line to get rid o the ensuing undefined reference to for various functions?

Errors:

using_plcmd.c:177:74: warning: invalid conversion from ‘void*’ to ‘bam_pileup1_t*’ [-fpermissive]
using_plcmd.c: In function ‘int mpileup(mplp_conf_t*, int, char**)’:
using_plcmd.c:215:32: warning: invalid conversion from ‘void*’ to ‘mplp_aux_t**’ [-fpermissive]
using_plcmd.c:216:31: warning: invalid conversion from ‘void*’ to ‘const bam_pileup1_t**’ [-fpermissive]
using_plcmd.c:217:32: warning: invalid conversion from ‘void*’ to ‘int*’ [-fpermissive]
using_plcmd.c:228:41: warning: invalid conversion from ‘void*’ to ‘mplp_aux_t*’ [-fpermissive]
using_plcmd.c:268:40: warning: invalid conversion from ‘void*’ to ‘int*’ [-fpermissive]
using_plcmd.c:269:40: warning: invalid conversion from ‘void*’ to ‘int*’ [-fpermissive]
using_plcmd.c:270:40: warning: invalid conversion from ‘void*’ to ‘bam_pileup1_t**’ [-fpermissive]
using_plcmd.c:276:35: warning: invalid conversion from ‘void*’ to ‘bcf_hdr_t*’ [-fpermissive]
using_plcmd.c:284:24: warning: invalid conversion from ‘void*’ to ‘char*’ [-fpermissive]
using_plcmd.c:291:25: warning: invalid conversion from ‘void*’ to ‘char*’ [-fpermissive]
using_plcmd.c:317:45: warning: invalid conversion from ‘void*’ to ‘bcf_callret1_t*’ [-fpermissive]
using_plcmd.c:352:40: warning: invalid conversion from ‘void*’ to ‘bcf1_t*’ [-fpermissive]
using_plcmd.c:368:34: warning: invalid conversion from ‘void*’ to ‘bcf1_t*’ [-fpermissive]
using_plcmd.c: In function ‘int read_file_list(const char*, int*, char***)’:
using_plcmd.c:458:40: warning: invalid conversion from ‘void*’ to ‘char**’ [-fpermissive]
using_plcmd.c:483:51: warning: invalid conversion from ‘void*’ to ‘char**’ [-fpermissive]
/tmp/ccPW1t2T.o: In function `mplp_func(void*, bam1_t*)':
using_plcmd.c:(.text+0xa1a): undefined reference to `bed_overlap(void const*, char const*, int, int)'
using_plcmd.c:(.text+0xa7b): undefined reference to `bcf_str2id'
using_plcmd.c:(.text+0xbc8): undefined reference to `bam_prob_realn_core(bam1_t*, char const*, int)'
using_plcmd.c:(.text+0xc00): undefined reference to `bam_cap_mapQ(bam1_t*, char*, int)'
/tmp/ccPW1t2T.o: In function `group_smpl(mplp_pileup_t*, bam_sample_t*, __kstring_t*, int, char* const*, int*, bam_pileup1_t const**, int)':
using_plcmd.c:(.text+0xd9b): undefined reference to `bam_smpl_rg2smid(bam_sample_t const*, char const*, char const*, __kstring_t*)'
using_plcmd.c:(.text+0xdcc): undefined reference to `bam_smpl_rg2smid(bam_sample_t const*, char const*, char const*, __kstring_t*)'
/tmp/ccPW1t2T.o: In function `mpileup(mplp_conf_t*, int, char**)':
using_plcmd.c:(.text+0x1119): undefined reference to `bam_smpl_init()'
using_plcmd.c:(.text+0x1380): undefined reference to `bam_smpl_add(bam_sample_t*, char const*, char const*)'
using_plcmd.c:(.text+0x13a8): undefined reference to `bcf_call_add_rg(void*, char const*, char const*)'
using_plcmd.c:(.text+0x1645): undefined reference to `bcf_open'
using_plcmd.c:(.text+0x1ac5): undefined reference to `bcf_hdr_sync'
using_plcmd.c:(.text+0x1ade): undefined reference to `bcf_hdr_write'
using_plcmd.c:(.text+0x1af7): undefined reference to `bcf_call_init'
using_plcmd.c:(.text+0x1de6): undefined reference to `bed_overlap(void const*, char const*, int, int)'
using_plcmd.c:(.text+0x202f): undefined reference to `bcf_call_glfgen'
using_plcmd.c:(.text+0x206b): undefined reference to `bcf_call_combine'
using_plcmd.c:(.text+0x20ac): undefined reference to `bcf_call2bcf'
using_plcmd.c:(.text+0x20c9): undefined reference to `bcf_write'
using_plcmd.c:(.text+0x20d5): undefined reference to `bcf_destroy'
using_plcmd.c:(.text+0x2127): undefined reference to `bcf_call_gap_prep'
using_plcmd.c:(.text+0x21ab): undefined reference to `bcf_call_glfgen'
using_plcmd.c:(.text+0x21e9): undefined reference to `bcf_call_combine'
using_plcmd.c:(.text+0x224a): undefined reference to `bcf_call2bcf'
using_plcmd.c:(.text+0x2267): undefined reference to `bcf_write'
using_plcmd.c:(.text+0x2273): undefined reference to `bcf_destroy'
using_plcmd.c:(.text+0x27af): undefined reference to `bcf_close'
using_plcmd.c:(.text+0x27be): undefined reference to `bam_smpl_destroy(bam_sample_t*)'
using_plcmd.c:(.text+0x2845): undefined reference to `bcf_call_del_rghash(void*)'
using_plcmd.c:(.text+0x2854): undefined reference to `bcf_hdr_destroy'
using_plcmd.c:(.text+0x2863): undefined reference to `bcf_call_destroy'
/tmp/ccPW1t2T.o: In function `main':
using_plcmd.c:(.text+0x2ed0): undefined reference to `bed_read(char const*)'
using_plcmd.c:(.text+0x313c): undefined reference to `bcf_str2id_init'
using_plcmd.c:(.text+0x31bb): undefined reference to `bcf_str2id_add'
using_plcmd.c:(.text+0x381d): undefined reference to `bcf_str2id_thorough_destroy'
using_plcmd.c:(.text+0x3871): undefined reference to `bed_destroy(void*)'

compile line:

g++ -I <samtools directory> -L <samtools directory> using_plcmd.c -o using_plcmd.o -lbam -lz -lpthread
samtools c • 3.8k views
ADD COMMENT
2
Entering edit mode
11.5 years ago
matted 7.8k

It would be better to use a makefile to do this, but if you really want to do it this way, this should work (it worked on my system):

We'll need libbam.a and libbcf.a:

make lib
cd bcftools
make lib
cd ../

Now make the binary with the appropriate dependencies and approximately the right compiler flags (check the original makefile):

gcc -Wall -I. using_plcmd.c -o using_plcmd bam2bcf.c bam2bcf_indel.c errmod.c sample.c -L. -lbam -Lbcftools -lbcf -lm -lz -lpthread
ADD COMMENT
0
Entering edit mode

thanks. I'm still getting an error "cannot find -lbcf", but can add bcf.c bcfutils.c and fetch.c into the compile in its place. So I see the libraries added are in the makefile in the line for samtools. Is there a way of finding out when you get an undefined reference what the name of the library is that contains the function?

ADD REPLY
0
Entering edit mode

Make sure you have the file bcftools/libbcf.a after the first steps. And make sure you give it the right library include directory -Lbcftools (the line break may have messed it up above).

There's not a failsafe automatic way to find the right library that I know of, because in general you could choose from multiple options to fulfill a certain requirement. I personally just search the source, but this is somewhat bad and doesn't scale.

ADD REPLY
0
Entering edit mode

oh, I didn't catch that -Lbcftools was the -L option and bcftools directory where libbcf was located, initially interpreted it as another library I just wasn't familiar with. I wasn't operating with a file in the samtools directory and was just adding in the full paths. Works now, thanks. I'm thinking that, based on what you've mentioned, one could look for all the .a files in whatever package and include all of them in the compile.

ADD REPLY

Login before adding your answer.

Traffic: 2605 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6