Hi Michael,

The quadruple slashes fixed the problem, thanks!

And it turns out that it is valid C++ to have
void main()

because it's valid C.

Source:
http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/legality-of-void-main.html

It would have made me very nervous to change the validation code from
the given configure.in file to change the return type, since I'm
imagining platforms that are distinct from mine (ie, unixy, and
therefore building C++ on top of C and not correcting the main return
type).

Thanks!
Mark
> ------------------------------
>
> Message: 3
> Date: Thu, 26 Aug 2010 23:10:09 +0200
> From: Michael Hertling <mhertl...@online.de>
> Subject: Re: [CMake] several questions about cmake
> To: cmake@cmake.org
> Message-ID: <4c76d831.5080...@online.de>
> Content-Type: text/plain; charset=ISO-8859-1
>
> 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

Reply via email to