Error message "‘asprintf’ was not declared in this scope" when compiling in Cygwin
MVEverett opened this issue · 7 comments
Hello
I'm trying to compile 2.1.13 in Cygwin64 and keep getting the following message
make
g++ -Wall -Wsign-compare -O3 -msse2 -mtune=core2 -Icityhash -g -c -o swarm.o swarm.cc
g++ -Wall -Wsign-compare -O3 -msse2 -mtune=core2 -Icityhash -g -c -o db.o db.cc
db.cc: In function ‘void db_read(const char*)’:
db.cc:407:32: error: ‘asprintf’ was not declared in this scope
missingabundance_lineno) == -1)
^
make: *** [Makefile:47: db.o] Error 1
Any suggestions for a fix?
I was able to solve this by adding an asprintf.h file I obtained from http://asprintf.insanecoding.org/ to the src folder and then adding
#include "asprintf.h" to the db.cc function
Crossplatform swarm!? 😄 💯
The asprintf function is a not available in all Unix variants. It's a GNU extension. It can be replaced by the alternative code that @MVEverett found. We should try to avoid such code in Swarm in the future to make it more portable. There is a similar function called xsprintf in vsearch in the util.cc file (currently lines 160-174).
Added xsprintf function to replace asprintf. Should solve the problem.
Removed need for asprintf or xsprintf.
Then, the xsprintf
function could be removed:
cppcheck --enable=all swarm/ 1> /dev/null
...
[swarm/src/util.cc:118]: (style) The function 'xsprintf' is never used.
[swarm/src/util.cc:108]: (style) The function 'xstrchrnul' is never used.
Unnecessary code removed.