I have a automake enabled project which I would like to compile with clang. I have added a configure option to enable clang:
AC_ARG_ENABLE([clang],
[AS_HELP_STRING([--enable-clang],[use clang instead of gcc as C compiler.])])
#Use C99 compilation mode
if test "x$enable_clang" = "xyes"; then
# clang uses c99 mode by default, so we just set CC to clang and we are done
CC="clang";
else
# We do not need to set CC as the default is gcc, but we need to set it to
# use C99 compilation mode
CFLAGS="$CFLAGS -std=c99";
fi
Further up in the file I have also the following two macros, to enable gettext functionality:
AM_GNU_GETTEXT_VERSION([0.18.1])
AM_GNU_GETTEXT([external])
If these two macros are present then configure ignores that the CC variable is set to clang and falls back to gcc. I have to comment out the gettext macros and then clang is used.
Obviously there is some problem with GETTEXT and clang. Am I using the wrong macro, or is clang not able to use the gnu gettext library? How can I fix this?
Have you tried to set CC to clang before you check for libraries (like gettext)? – Some programmer dude
Nice that worked. – lanoxx
Related
I am trying to force CMake to pass std=gnu17 instead of std=c17 to GCC.
I tried:
set_property(TARGET "${MyProject_${Compile_Type}_NAME}" PROPERTY C_STANDARD gnu17)
in the CMakeLists.txt but I get the following error:
CMake Error at CMakeLists.txt:260 (add_executable):
C_STANDARD is set to invalid value 'gnu17'
The same happens when I try gnu11 instead of gnu17.
The reason I want it to pass the flag is that I am using one of the GCC extensions and that produces a warning when using -pedantic warning levels (which I would prefer to keep using).
Please notice this is specifically about C, not C++.
Usually, CMake will use -std=gnu17 with plain C_STANDARD 17.
But if you want to be sure that CMake will use compiler-specific extensions, then you may set also C_EXTENSIONS property:
set_target_properties(<...> PROPERTIES
C_STANDARD 17
C_EXTENSIONS ON
)
If your code works only with a specific compiler and its extentions, then you probably want to also check a compiler:
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
message(FATAL_ERROR "The project requires g++ to be used as C++ compiler"
endif()
In the gcc compiler we can provide a macro to be used by the preprocessor in C using -D flag (example- gcc -DN=10 test.c)
What is the flag that can be used to do the same in the clang compiler?
When I give the same -D option to the clang compiler on Windows, it gives an error:
"Directory not found."
Answer is the 2 comments from #cremno and #FUZxxl above.
The error wasn't coming from the clang compiler although it said clang error. Rather it was coming from the Windows cmd which looks for a directory after the '=' sign.
With IBM's cc compiler there is one option -brtl.
cc-brtl .....
This option does the following:-
-brtl Tells the linkage editor to accept both .so and .a library file types.
I am using gcc compiler now on ubuntu. I want to know what is the corresponding option in gcc to achieve
the same thing?
You don't need that option for gcc. The link editor will accept both so and a files by default, with so files being preferred. You can think of gcc as having the opposite behaviour to IBM's C compiler: The behaviour without any options is as if you provided -brtl to IBM's C compiler, while the option -static turns of dynamic linking (and thus causes gcc to not take so files into consideration), which is as if you didn't specify -brtl to IBM's C compiler.
I need to compile a code written in C using gcc (in Xcode) with flag options -ansi -pedantic. I know how to change the compiler to gcc, however I don't know how to change the flags.
Thanks in advance.
Use the Other C Flags build setting to add compiler flags that aren't available in Xcode's build settings editor.
I'm writing a shared library using autoconf/libtool which I want to compile for Linux and for Windows (Using the mingw cross-compiler). For Linux (and maybe other platforms which support it) I need to set -fPIC. So I put it into the CFLAGS in Makefile.am. But when I cross-compile it with mingw then gcc complains with a warning:
warning: -fPIC ignored for target (all code is position independent)
So obviously this option is not needed for Windows code. It is only a warning but I want to get rid of it anyway. How can I do this? Maybe there is already a libtool/autoconf feature which checks if the option is supported and only sets it when needed so I don't have to do this manually in Makefile.am?
You shouldn't need to set -fPIC manually, libtool will add it if you tell it what type of binary/library you're building.
lib_LTLIBRARIES = mylibrary.la
mylibrary_la_SOURCES = mylibrary.c
This can produce both a mylibrary.so with PIC (if needed) and a mylibrary.a without, depending on other Autoconf/Automake options. (Probably something like .dll and .lib on Windows, but I don't use that platform.)
I have used the following in configure.ac to add -fPIC conditionally:
AC_MSG_CHECKING(whether fPIC compiler option is accepted)
SAVED_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -fPIC -Werror"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
[AC_MSG_RESULT(yes)
CFLAGS="$SAVED_CFLAGS -fPIC"],
[AC_MSG_RESULT(no)
CFLAGS="$SAVED_CFLAGS"])