3 ms·
I wanted to give it a try, but if fails without considering the target attribute ... > gcc test.c -g > test.c:9:5: error: redefinition of ‘foo’ > int foo (
by wazari972 12y ago
I wanted to give it a try, but if fails without considering the target attribute ...
> gcc test.c -g
> test.c:9:5: error: redefinition of ‘foo’
> int foo ()
> gcc version 4.9.2 (GCC) (archlinux)
- zimbu668 12y agoIt only works with c++, your command failed for me, try renaming the file: gcc test.cpp -g or use the c++ compiler explicitly: g++ test.c -g
- mineo 12y agoThat's because gcc is trying to compile it as C, not C++. You need to call the file "test.cpp" or explicitly use g++ instead of gcc to compile it. (You'll also need to "#include <assert.h>" or it won't compile.)
- nkurz 12y agoIt's not entirely clear, but I think this is a C++ only feature that is only available when using the GCC C++ front end (g++). The linked document includes the ambiguous "Support is only available in C++ for i386 targets", but other sources (such as the GCC 4.9.2 documentation) have clarified this to "With the GNU C++ front end, for target i386, you may specify multiple versions of a function". https://gcc.gnu.org/onlinedocs/gcc-4.9.2/gcc/Function-Multiversioning.html https://gcc.gnu.org/onlinedocs/gcc-4.9.2/gcc/Function-Multiv...
- wazari972 12y agoindeed, my bad! to my defense, the code looks a lot like C code ;-)