Closed iAvicenna closed 1 year ago
Hi,
No problem. I suggest you look at the Makefile
build system. It will prompt the complete command lines you need. For example:
> make clean all
And you will see that, to compile an example, you can use the following command:
> gcc -Wall -g -O3 -march=native -L../lib -I.. wfa_basic.c -o bin/wfa_basic -lwfa -fopenmp -lm -lrt
Note the -L
option to provide the linking libraries path and -I
to provide the includes path.
Give it a try.
Thanks for the reply. So I managed to achieve some progress but now am stuck at an error which this time might be code related (an error about begin_timer, see below). Just for background information, project folder structure is as follows:
WFA2-lib\
git\
build\
install\
I clone the library to git and install dir is install. From the build folder I called the following
cmake ../git -DCMAKE_BUILD_TYPE=Release -DEXTRA_FLAGS="-ftree-vectorize -msse2 -mfpmath=sse -ftree-vectorizer-verbose=5" -DBUILD_SHARED_LIBS=ON -DOPENMP=TRUE -DCMAKE_INSTALL_PREFIX=../install
make
cmake --build . --verbose
Then following your suggestion I compiled the following code (only containing headers) from the parent of WFA2-lib
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include "wavefront/wavefront_align.h"
via
gcc -Wall -g -O3 -march=native -L"./WFA2-lib/install/lib" -I"./WFA2-lib/install/include/wfa2lib" wfa_example.c -o wfa_example -lwfa -fopenmp -lm -lrt
Note that include dir is "./WFA2-lib/install/include/wfa2lib", when I tried only ""./WFA2-lib/install/include/" it did not work (gave an error saying that could not find utils etc and had to change the header to "wfa2lib/wavefront/wavefront_align.h"). After this it complained about some missing types such as FILE, bool, uint64_t so I added the necessary headers to the code I wrote above. So finally when I compiled the code above, I got the error message:
In file included from ./WFA2-lib/install/include/wfa2lib/wavefront/wavefront_aligner.h:36,
from ./WFA2-lib/install/include/wfa2lib/wavefront/wavefront_align.h:34,
from wfa_example.c:4:
./WFA2-lib/install/include/wfa2lib/system/profiler_timer.h:53:35: warning: ‘struct timespec’ declared inside parameter list will not be visible outside of this definition or declaration
53 | void timer_get_system_time(struct timespec *ts);
| ^~~~~~~~
./WFA2-lib/install/include/wfa2lib/system/profiler_timer.h:60:19: error: field ‘begin_timer’ has incomplete type
60 | struct timespec begin_timer; // Timer begin
| ^~~~~~~~~~~
Is this a bug? Or do I need to do things differently. On a side note I did not also quite understand your suggestion to look at the "Makefile build system". Do you mean to look inside CMakeLists.txt or Makefile itself? Where does it prompt the necessary steps?
Yes, it seems you just have to include the headers you are missing.
1) Try including wfa.h
instead on your wfa_example.c
.
2) Otherwise, include directly "system/profiler_timer.h"
Let me know
Okay, I thought timespec was something that was defined inside this package but it seems to come from time.h so including that resolved that problem. Now I will try to compile the example given in the main page. Thanks
Okay so I think I am running into one final problem. I tried compiling the following code:
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <time.h>
#include <string.h>
#include "wavefront/wavefront_align.h"
#include "wavefront/wfa.h"
#include "wavefront/wavefront_attributes.h"
int main(void){
wavefront_aligner_attr_t attributes = wavefront_aligner_attr_default;
attributes.distance_metric = gap_affine;
attributes.affine_penalties.mismatch = 4;
attributes.affine_penalties.gap_opening = 6;
attributes.affine_penalties.gap_extension = 2;
// Initialize Wavefront Aligner
wavefront_aligner_t* const wf_aligner = wavefront_aligner_new(&attributes);
}
First of all if I try to compile it with -lwfa it complains that
/usr/bin/ld: cannot find -lwfa
If I try to compile it without it, it says that
/usr/bin/ld: /tmp/ccO1g70z.o: in function `main':
/home/avicenna/Downloads/wfa_example.c:12: undefined reference to `wavefront_aligner_attr_default'
/usr/bin/ld: /home/avicenna/Downloads/wfa_example.c:18: undefined reference to `wavefront_aligner_new'
So I assume, I am supposed to use -lwfa but somehow I have not built and installed correctly so that it can not find it (I have added /install/lib to PATH)?
I feel we are back to the first problem of linking the library. Why don't you share your wfa_example.c
? I can try to set it up as an example.
It is the exact same code I wrote in the previous message. I uploaded it to here:
I compiled it using:
gcc -Wall -g -O3 -march=native -L"./WFA2-lib/install/lib" -I"./WFA2-lib/install/include/wfa2lib" wfa_example.c -o wfa_example -lwfa -fopenmp -lm -lrt
My project folder structure is as follows
WFA2-lib\
git\
build\
install\
I called the command above from parent of WFA2-lib. It seems that -I options is correctly specified since without it it can not find the headers. But maybe as you said something is wrong with -L or where it points to?
The contents of the /install/lib are: libwfa2.so, libwfa2.so.0, libwfa2cpp.a, libwfa2cpp.so, libwfa2cpp.so.0
Ok, let's go step-by-step.
git clone https://github.com/smarco/WFA2-lib WFA2.example
cd WFA2.example
cp $(EXAMPLE_PATH)/wfa_example.c . ## Copy wfa_example.c inside the WFA2 folder
make clean all
I cleaned a bit you example:
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <time.h>
#include <string.h>
#include "wavefront/wfa.h"
int main(void){
wavefront_aligner_attr_t attributes = wavefront_aligner_attr_default;
attributes.distance_metric = gap_affine;
attributes.affine_penalties.mismatch = 4;
attributes.affine_penalties.gap_opening = 6;
attributes.affine_penalties.gap_extension = 2;
// Initialize Wavefront Aligner
wavefront_aligner_t* const wf_aligner = wavefront_aligner_new(&attributes);
}
And then, we compile your example.
gcc -Wall -g -O3 -march=native -L./lib -I. wfa_example.c -o wfa_example -lwfa -fopenmp -lm -lrt
That should work!
Hi,
I am trying to build WFA2-lib and use it without any bindings directly as a C library. I am on ubuntu 20.04 (cmake version 3.16.3, gcc version 9.4.0, make version 4.2.1). I think I have managed to build it correctly but am having difficulty calling the library in a .c file. The way I built it is as follows:
This runs without any errors or problems. I then tried the first example in the main page but when I tried to compile the code using
gcc -O3 wfa_example.c -o wfa_example -lwfa
I get the error
The same happens with the minimal example of simply having a code which includes the following:
If I try to remove the second line (including the wavefront_align) and compile the code using the same command above I get
/usr/bin/ld: cannot find -lwfa
I have added WFA2-lib/bin and WFA2-lib/lib in the PATH variable but I still get the same error. I am kind of a novice when it comes to building C libraries from source and using them so I am assuming that I have not set some paths correctly, have not used the headers correctly or compiled the example code correctly. Please let me know how I could solve this issue.
Thanks