On 08/26/2010 05:38 PM, Mark Roden wrote: >>> 2) I'm trying to check to see if a certain C++ code chunk will >>> compile. The line is: >>> >>> CHECK_CXX_SOURCE_COMPILES(" >>> #include <string.h> >>> #include <stdio.h> >>> void main(){ >>> char buf[100]; >>> char buf2[100]; >>> strncpy(buf2, buf, 5); >>> buf2[5] = '\0'; >>> puts(buf2); >>> }" EXTERN_C) >>> >>> The EXTERN_C test is failing here. The problem is, I can cut and >>> paste that code into a blank project in vs2008 and it compiles just >>> fine. Is there a way to see the compiler error, or to determine why >>> that would fail? >>> >>> The code in the configure.in file is: >>> >>> AC_TRY_LINK([ >>> # include <string.h> >>> # include <stdio.h> >>> ], [ >>> char buf[100]; >>> strcpy(buf, "Hello world\n"); >>> ], >>> bz_cv_cplusplus_needexternCwrapper=no, >>> bz_cv_cplusplus_needexternCwrapper=yes) >>> ]) >>> >>> I can't use that directly (or can I?) because the quotation marks in >>> "Hello World" prematurely cut off the code in the SOURCE section of >>> CHECK_CXX_SOURCE_COMPILES, and I get an error that the variable World" >>> makes no sense. >> >> Just put \ in front of the quotation marks, and the hello world code will >> work. > > That's not my point. The code I gave has no double quotes in it, and > it still doesn't compile properly, but it does compile and work in a > visual studio environment. > If I do: > > CHECK_CXX_SOURCE_COMPILES(" > #include <string.h> > #include <stdio.h> > void main(){ > char buf[100]; > strcpy(buf, \"Hello world\n\"); > }" EXTERN_C) > > I get > > Performing Test EXTERN_C > Performing Test EXTERN_C - Failed > > But that code compiles in an empty vs2008 project. > > How can I get the compiler error? I don't see why this code test should > fail.
You need to escape the newline in the string literal four-fold, i.e. \"Hello world\\\\n\". Moreover, "void" isn't allowed as the return type of main() in C++, use "int" instead. Regards, Michael _______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake