compiler-flags

How to build nodejs C++ addon depending on a shared library with relative location

自闭症网瘾萝莉.ら 提交于 2019-12-04 16:28:58
I'm trying to build a node.js C++ using node-gyp but can't figure out how to specify the -Wl,-rpath,$ORIGIN so that when loaded from node it could find shared object library that is in the same directory as addon.node . I have tried setting my binding.gyp like this: "libraries": [ "-L../../install_release_x64/", "-llibppp" ], "ldflags": [ "-Wl,-rpath,'$ORIGIN'" ], "cflags_cc": [ "-fexceptions", "-fPIC", "-Wno-unknown-pragmas" ] but when I run $ readelf -d addon.node the result is like this: Dynamic section at offset 0x7d10 contains 29 entries: Tag Type Name/Value 0x0000000000000001 (NEEDED)

How to add std=c++11 flag to clang-cl?

做~自己de王妃 提交于 2019-12-04 16:23:28
I tried to compile a C++11 program with clang-cl under Windows. Clang-cl is the wrapper around clang to be more compatible with cl (Visual Studio compiler). I tried to add -std=c++11 and /std=c++11 and both get rejected. This is to no surprise as cl has no C++11 flag. But I can not use C++11 features with clang-cl. How can I enable C++11 support in clang-cl? In the documentation mentioned before says: http://clang.llvm.org/docs/UsersManual.html#clang-cl clang defaults to C++11 for Windows targets. Maybe you don't need to pass any flag to clang-cl. From official docs : /std:<standard> 来源: https

What's the differrence among cflgs sse options of -msse, -msse2, -mssse3, -msse4 rtc..? and how to determine?

六眼飞鱼酱① 提交于 2019-12-04 09:18:12
问题 For the GCC CFLAGS options: -msse , -msse2 , -mssse3 , -msse4 , -msse4.1 , -msse4.2 . Are they exclusive in their use or can the be used together? My understanding is that the choosing which to set depends on whether the target arch, which the program will run on, supports it or not, is this correct? If so, how could I know what sse my target arch supports? In Linux, I cat /proc/cpuinfo, but what if mac or Windows? Thanks! 回答1: The -m switched can be used in parallel, furthermore some of them

Undefined behavior from pointer math on a C++ array

戏子无情 提交于 2019-12-04 08:57:23
问题 Why the output of this program is 4 ? #include <iostream> int main() { short A[] = {1, 2, 3, 4, 5, 6}; std::cout << *(short*)((char*)A + 7) << std::endl; return 0; } From my understanding, on x86 little endian system, where char has 1 byte, and short 2 bytes, the output should be 0x0500 , because the data in array A is as fallow in hex: 01 00 02 00 03 00 04 00 05 00 06 00 We move from the beginning 7 bytes forward, and then read 2 bytes. What I'm missing? 回答1: You are violating strict

Is it realistic to use -O3 or -Ofast to compile your benchmark code or will it remove code?

浪尽此生 提交于 2019-12-04 04:14:57
问题 When compiling the benchmark code below with -O3 I was impressed by the difference it made in latency so i began to wonder whether the compiler is not "cheating" by removing code somehow. Is there a way to check for that? Am I safe to benchmark with -O3 ? Is it realistic to expect 15x gains in speed? Results without -O3 : Average: 239 nanos Min: 230 nanos (9 million iterations) Results with -O3 : Average: 14 nanos, Min: 12 nanos (9 million iterations) int iterations = stoi(argv[1]); int load

What exactly does GCC -fobjc-direct-dispatch option do?

喜夏-厌秋 提交于 2019-12-04 04:14:53
问题 The GCC manual says: -fobjc-direct-dispatch Allow fast jumps to the message dispatcher. On Darwin this is accomplished via the comm page. Can I assume this flag eliminates dynamic dispatch? How does it work? I believe it should be as fast as a C function call if it is linked directly. 回答1: No, the dynamic dispatch is still there (calls still route through objc_msgSend ). And this option doesn't introduce any difference currently with x86(-64). From http://developer.apple.com/legacy/mac

Should I use “-ansi” or explicit “-std=…” as compiler flags?

≡放荡痞女 提交于 2019-12-04 00:59:00
I've read that ANSI C is not exactly the same as ISO C and compilers may differ in interpretation of what "-ansi" is about. (gcc maps it to C90, clang maps it to C89) At the moment I would tend to use "-std=..." over "-ansi" as then it is explicitly shown which standard is used. As I am specifically interested in compiling on Linux, Windows and MAC, I fear some compilers could not understand "-std=..." but "-ansi". So are there any pros and cons for using the one over the other? If you want the compiler to enforce the 1989 ANSI C standard, or equivalently the 1990 ISO C standard (they describe

Why can't clang enable all sanitizers?

拜拜、爱过 提交于 2019-12-03 22:39:17
Clang has various sanitizers that can be turned on to catch problems at runtime. However, there are some sanitizers that I can't use together. Why is that? clang++-3.9 -std=c++1z -g -fsanitize=memory -fsanitize=address -o main main.cpp 1 clang: error: invalid argument '-fsanitize=address' not allowed with '-fsanitize=memory' It's not a big deal, but when I run my unit tests, it takes longer than it should, because I have create multiple binaries for the same tests, and run each of them separately. clang++-3.9 -std=c++1z -g -fsanitize=address -o test1 test.cpp clang++-3.9 -std=c++1z -g

How to force xcode to use ARC on a specific file?

谁都会走 提交于 2019-12-03 15:35:50
问题 My project contains XMPPFramework which contains a file that has to be used with ARC. But my project is Non ARC and cannot be converted due to certain other libraries linked to it. How do I force the compiler to use ARC only on a certain class ? 回答1: It is the inverse problem of this question. The difference is that you would use -fobjc-arc instead of -fno-objc-arc . 来源: https://stackoverflow.com/questions/13392521/how-to-force-xcode-to-use-arc-on-a-specific-file

Mixing PIC and non-PIC objects in a shared library

喜你入骨 提交于 2019-12-03 14:25:21
This question is related to this one as well as its answer. I just discovered some ugliness in a build I'm working on. The situation looks somewhat like the following (written in gmake format); note, this specifically applies to a 32-bit memory model on sparc and x86 hardware: OBJ_SET1 := some objects OBJ_SET2 := some objects # note: OBJ_SET2 doesn't get this flag ${OBJ_SET1} : CCFLAGS += -PIC ${OBJ_SET1} ${OBJ_SET2} : %.o : %.cc ${CCC} ${CCFLAGS} -m32 -o ${@} -c ${<} obj1.o : ${OBJ_SET1} obj2.o : ${OBJ_SET2} sharedlib.so : obj1.o obj2.o obj1.o obj2.o sharedlib.so : ${LINK} ${LDFLAGS} -m32