torognes / swarm

A robust and fast clustering method for amplicon-based studies
GNU Affero General Public License v3.0
123 stars 23 forks source link

Error message "‘asprintf’ was not declared in this scope" when compiling in Cygwin #100

Closed MVEverett closed 7 years ago

MVEverett commented 7 years ago

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?

MVEverett commented 7 years ago

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

colinbrislawn commented 7 years ago

Crossplatform swarm!? 😄 💯

torognes commented 7 years ago

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).

torognes commented 7 years ago

Added xsprintf function to replace asprintf. Should solve the problem.

torognes commented 7 years ago

Removed need for asprintf or xsprintf.

frederic-mahe commented 7 years ago

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.
torognes commented 7 years ago

Unnecessary code removed.