clang

Getting warning “include location '/usr/local/include' is unsafe for cross-compilation” every time I try to compile using `clang -Weverything`

泪湿孤枕 提交于 2021-02-10 14:19:41
问题 Apologies if this question isn't clear, I'm struggling to even start debugging this issue. I'm on macOS and I'm now getting the following error / warning every time I compile C programs using clang with -Weverything and -Werror flags: error: include location '/usr/local/include' is unsafe for cross-compilation [-Werror,-Wpoison-system-directories] Initially I thought this was an issue related to my code, but I discovered that this error now occurs with every program I try to compile. I've

Type casting: double to char: multiple questions

核能气质少年 提交于 2021-02-10 10:41:47
问题 Consider this code: #include <stdio.h> int main(void) { /* TEST 1 */ double d = 128; char ch = (char)d; printf("%d\n", ch); /* TEST 2 */ printf("%d\n", (char)128.0); /* TEST 3 */ char ch1 = (char)128.0; printf("%d\n", ch1); return 0; } Results: gcc* clang* cl* TEST 1 -128 -128 -128 TEST 2 127 0 -128 TEST 3 127 -2 -128 * latest version Questions: Why the results differ between tests (excluding cl )? Why the results differ between compilers (excluding TEST 1 )? In case of UB/IB, where is the UB

Type casting: double to char: multiple questions

南笙酒味 提交于 2021-02-10 10:41:26
问题 Consider this code: #include <stdio.h> int main(void) { /* TEST 1 */ double d = 128; char ch = (char)d; printf("%d\n", ch); /* TEST 2 */ printf("%d\n", (char)128.0); /* TEST 3 */ char ch1 = (char)128.0; printf("%d\n", ch1); return 0; } Results: gcc* clang* cl* TEST 1 -128 -128 -128 TEST 2 127 0 -128 TEST 3 127 -2 -128 * latest version Questions: Why the results differ between tests (excluding cl )? Why the results differ between compilers (excluding TEST 1 )? In case of UB/IB, where is the UB

编译FFmpeg

陌路散爱 提交于 2021-02-10 08:12:01
编译FFmpeg,这是一个古老的话题,但是小程还是介绍一遍,就当是记录。 小程之前介绍怎么给视频添加水印时,就已经提到FFmpeg的编译,因为需要在编译时指定滤镜的功能,读者可以关注“广州小程”微信公众号并查阅这篇文章(音视频->FFmpeg应用)。 但是,在手机盛行的时代,读者可能更需要的是能在iOS或Android平台上运行的FFmpeg,而对于命令行的ffmpeg,读者可以在个人电脑上面使用(因为它简洁易操作),也可以在服务程序中使用(安装FFmpeg后直接调用ffmpeg命令),比如小程经常在自己的mac机上使用ffmpeg命令。 本文介绍如何编译出iOS或Android平台使用的FFmpeg链接库。 正如编译macos平台使用的FFmpeg一样,编译iOS或Android平台使用的FFmpeg,主线也是先configure再make,只不过,有更多的细节需要考虑。 小程使用的是macos系统。 (1)编译环境准备 (a)pkg-config FFmpeg在编译时经常使用到第三方库(比如x264、rtmp等),编译器在查找这些第三方库的头文件与库文件时,需要使用到程序pkg-config。 pkg-conifig给编译器提供路径与链接选项。第三方库在make install时会生成pc后缀的文件并拷贝到系统目录,而pkg-config就是从这个pc文件读取出路径信息。

How can I indicate that the memory *pointed* to by an inline ASM argument may be used?

房东的猫 提交于 2021-02-10 06:56:53
问题 Consider the following small function: void foo(int* iptr) { iptr[10] = 1; __asm__ volatile ("nop"::"r"(iptr):); iptr[10] = 2; } Using gcc, this compiles to: foo: nop mov DWORD PTR [rdi+40], 2 ret Note in particular, that the first write to iptr , iptr[10] = 1 doesn't occur at all: the inline asm nop is the first thing in the function, and only the final write of 2 appears (after the ASM call). Apparently the compiler decides that it only needs to provide an up-to-date version of the value of

How can I indicate that the memory *pointed* to by an inline ASM argument may be used?

百般思念 提交于 2021-02-10 06:56:16
问题 Consider the following small function: void foo(int* iptr) { iptr[10] = 1; __asm__ volatile ("nop"::"r"(iptr):); iptr[10] = 2; } Using gcc, this compiles to: foo: nop mov DWORD PTR [rdi+40], 2 ret Note in particular, that the first write to iptr , iptr[10] = 1 doesn't occur at all: the inline asm nop is the first thing in the function, and only the final write of 2 appears (after the ASM call). Apparently the compiler decides that it only needs to provide an up-to-date version of the value of

unknown type name 'siginfo_t' with Clang using _POSIX_C_SOURCE 2, why?

走远了吗. 提交于 2021-02-08 15:34:11
问题 Update Turnes out my lecturer will accept code written to the GNU99 standard, so, as User1 pointed out, I used _GNU_SOURCE at the beginning of my program. (See man feature_test_macros for more info.) Thanks for helping me understand! On Ubuntu 13.10 with Clang 3.4, GCC 4.8.1, I am doing an assignment which requires me to use the C99 standard. (I also have GNUstep installed from SVN) WRT GCC, I think I have 4 versions installed in these folders: /usr/lib/gcc/x86_64-linux-gnu/4.7 /usr/lib/gcc

Compile-time counter in template class

◇◆丶佛笑我妖孽 提交于 2021-02-08 14:57:59
问题 I have a compile-time counter that I used for years, inspired by these answers. It works in C++03/11, and as far as I tested, relatively well on major compilers: namespace meta { template<unsigned int n> struct Count { char data[n]; }; template<int n> struct ICount : public ICount<n-1> {}; template<> struct ICount<0> {}; #define MAX_COUNT 64 #define MAKE_COUNTER( _tag_ ) \ static ::meta::Count<1> _counter ## _tag_ (::meta::ICount<1>) #define GET_COUNT( _tag_ ) \ (sizeof(_counter ## _tag_ (:

Private member access in template substitution and SFINAE

僤鯓⒐⒋嵵緔 提交于 2021-02-08 12:21:37
问题 class A { int a; }; template<typename, typename = void> class test {}; template<typename T> class test<T,decltype(T::a)> {}; int main() { test<A> a; } The code above compiles without error on clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final) , but fails to compile on g++-5 (Ubuntu 5.4.1-2ubuntu1~16.04) 5.4.1 20160904 and g++-6 (Ubuntu 6.2.0-3ubuntu11~16.04) 6.2.0 20160901 with errors like this: main.cpp: In function ‘int main()’: main.cpp:9:22: error: ‘int A::a’ is private within this

Private member access in template substitution and SFINAE

感情迁移 提交于 2021-02-08 12:20:57
问题 class A { int a; }; template<typename, typename = void> class test {}; template<typename T> class test<T,decltype(T::a)> {}; int main() { test<A> a; } The code above compiles without error on clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final) , but fails to compile on g++-5 (Ubuntu 5.4.1-2ubuntu1~16.04) 5.4.1 20160904 and g++-6 (Ubuntu 6.2.0-3ubuntu11~16.04) 6.2.0 20160901 with errors like this: main.cpp: In function ‘int main()’: main.cpp:9:22: error: ‘int A::a’ is private within this