how golang buildmode=c-shared without -fpic - go

I want a dynamic library that build without -fPIC, so that I can keep multi instance in memory through loading a same library multi times, here is my env
go version go1.15.11 linux/amd64
go env
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build963217559=/tmp/go-build -gno-record-gcc-switches"
the problem is that the GOGCCFLAGS is not configurable, how can i run go build -buildmode=c-shared without -fPIC?

Related

Unable to create latest headless chrome for AWS Lambda

I have required to use the latest headless chrome with puppeteer on AWS Lambda and for that, I have referred: https://github.com/adieuadieu/serverless-chrome/blob/master/docs/chrome.md.
I already tried all the following approch to create headless chrome using given instruction but won't work and will get the same error as below.
Locally (build headless Chromium locally is with Docker)
With AWS EC2 (build Chromium using an EC2 Spot Instance (spot-block))
AmazonLinux on EC2 (build Chromium without Docker using just the build.sh script)
ERROR:
ninja: Entering directory `out/Headless'
[1/26797] STAMP obj/build/win/default_exe_manifest.stamp
[2/26797] ACTION //build/util:webkit_version(//build/toolchain/linux:clang_x64)
[3/26797] STAMP obj/base/numerics/base_numerics.stamp
[4/26797] ACTION //base:build_date(//build/toolchain/linux:clang_x64)
[5/26797] STAMP obj/build/buildflag_header_h.stamp
[6/26797] STAMP obj/base/util/type_safety/type_safety.stamp
[7/26797] CXX obj/base/base_static/base_switches.o
FAILED: obj/base/base_static/base_switches.o
../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF obj/base/base_static/base_switches.o.d -DUSE_AURA=1 -DUSE_NSS_CERTS=1 -DUSE_OZONE=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -DCR_CLANG_REVISION=\"373424-64a362e7-1\" -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D_FORTIFY_SOURCE=2 -D_LIBCPP_ABI_UNSTABLE -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS -D_LIBCPP_ENABLE_NODISCARD -DCR_LIBCXX_REVISION=361348 -DCR_SYSROOT_HASH=bcc994cc6e5d4d6f0eec8b44e7f0a65f5a1a7b90 -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -I../.. -Igen -fno-strict-aliasing --param=ssp-buffer-size=4 -fstack-protector -funwind-tables -fPIC -B../../third_party/binutils/Linux_x64/Release/bin -pthread -fcolor-diagnostics -fmerge-all-constants -fcrash-diagnostics-dir=../../tools/clang/crashreports -Xclang -mllvm -Xclang -instcombine-lower-dbg-declare=0 -fcomplete-member-pointers -m64 -march=x86-64 -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -no-canonical-prefixes -Wall -Werror -Wextra -Wimplicit-fallthrough -Wthread-safety -Wextra-semi -Wno-missing-field-initializers -Wno-unused-parameter -Wno-c++11-narrowing -Wno-unneeded-internal-declaration -Wno-undefined-var-template -Wno-ignored-pragma-optimize -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-reorder-init-list -Wno-final-dtor-non-final-class -Wno-sizeof-array-div -fno-omit-frame-pointer -g0 -fvisibility=hidden -Xclang -add-plugin -Xclang find-bad-constructs -Xclang -plugin-arg-find-bad-constructs -Xclang check-ipc -Wheader-hygiene -Wstring-conversion -Wtautological-overlap-compare -O2 -fno-ident -fdata-sections -ffunction-sections -std=c++14 -fno-exceptions -fno-rtti -nostdinc++ -isystem../../buildtools/third_party/libc++/trunk/include -isystem../../buildtools/third_party/libc++abi/trunk/include --sysroot=../../build/linux/debian_sid_amd64-sysroot -fvisibility-inlines-hidden -c ../../base/base_switches.cc -o obj/base/base_static/base_switches.o
../../third_party/llvm-build/Release+Asserts/bin/clang++: /lib64/libc.so.6: version `GLIBC_2.18' not found (required by /build/chromium/src/third_party/llvm-build/Release+Asserts/bin/../lib/libstdc++.so.6)
ninja: build stopped: subcommand failed.
The command '/bin/sh -c sh /build.sh' returned a non-zero code: 1
The way of implementation/orchestration was changed in a lambda to use headless chrome with puppeteer compared to earlier.
I have used chrome-aws-lambda to run headless chrome with puppeteer in lambda for Nodejs10.x/12.x. Amazon has already announced EOL (End Of Life) for Nodejs8.x in lambda.
Amazon is using Amazon Linux AMI 2 for Node.js10.x/12.x and Amazon Linux AMI for Node.js8.x. Amazon Linux AMI 2 does not have some of the dependencies which will create problems to run headless chrome with puppeteer in Nodejs10.x/12.x inside lambda and therefore will use the lambda layer to run headless chrome with puppeteer on Node.js10.x/12.x.
chrome-aws-lambda will provide us the latest version of puppeteer and headless chrome.
I have had this problems as well, if is not required for your app to be hosted on AWS. The easiest way, to put your app in the cloud is by using Google Cloud Functions with a decent amount of RAM. Here is a video showing you how: https://www.youtube.com/watch?v=i8THvr03FaY

yocto: failing to find Python.h and cross compiling fails

Im using poky version of yocto, and adding zbar library in my yocto build. I found a readymade recipe at http://cgit.openembedded.org/meta-openembedded/tree/meta-oe/recipes-support/zbar/zbar_0.10.bb and modified it a bit to get working with poky. I got it working fine with imagemagick, and the compiled zbarimg works on the target board.
The modified recipe is available here: http://paste.ubuntu.com/25725000/
When I proceed configuring python support (--with-python) to the build, some dependency issues crept up, which Im unable to resolve.
It appears as if the compiler doesn't find the appropriate headers, since the include paths don't contain appropriate folder.
The full compiler command is:
arm-poky-linux-gnueabi-libtool: compile: arm-poky-linux-gnueabi-gcc -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/home/jlumme/imx_build/build-x11-pico-imx6ul/tmp/sysroots/pico-imx6ul-emmc -DHAVE_CONFIG_H -I. -I/home/jlumme/imx_build/build-x11-pico-imx6ul/tmp/work/cortexa7hf-vfp-neon-poky-linux-gnueabi/zbar/0.10-r0/zbar-0.10 -I./include -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -I/usr/include/python2.7 -I/usr/include/python2.7 -I/home/jlumme/imx_build/build-x11-pico-imx6ul/tmp/work/cortexa7hf-vfp-neon-poky-linux-gnueabi/zbar/0.10-r0/zbar-0.10/include -Wall -Wno-parentheses -O2 -pipe -g -feliminate-unused-debug-types -c /home/jlumme/imx_build/build-x11-pico-imx6ul/tmp/work/cortexa7hf-vfp-neon-poky-linux-gnueabi/zbar/0.10-r0/zbar-0.10/python/symbol.c -fPIC -DPIC -o python/.libs/python_zbar_la-symbol.o
You can see that sysroot variable is set, and it appears like the right location, and there is /usr/include/python2.7 there, though its pointing right at the host system include path.
There is a warning from compiler: cc1: warning: include location "/usr/include/python2.7" is unsafe for cross-compilation [-Wpoison-system-directories] which I don't know why it happens, but it seems like the python2.7 folder is appropriately looked at, just not under the sysroot (my host system doesn't have /usr/lib/python2.7)
If I go to the sysroot include (/home/jlumme/imx_build/build-x11-pico-imx6ul/tmp/sysroots/pico-imx6ul-emmc/usr/include/) folder, I can see that it has a subfolder python2.7. If under this usr/include folder I add a symlink Python.h -> python2.7/Python.h, the compiler will complain about the next header file which is not found.
So to me it seems, all I should do is add the appropriate 'sysroot' + usr/include/python2.7 as include search folder it would compile happily - but Im not sure how..
The full compilation log is available here: http://paste.ubuntu.com/25725014/
This is a bug in the zbar configure script.
Try inheriting pythonnative so the configure script can run a compatible Python to know where to look.

Force CMake in verbose mode via Gradle and the Android NDK

I'm using Gradle and CMake to compile an Android NDK project from the command line. Previously, I was using Ant and ndk-build but I'm trying to migrate the project completely to Gradle and CMake.
In my build.gradle I have the following lines to invoke CMake:
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
}
}
Now how can I force CMake to print all compiler calls to the console before it makes them? Specifically, I want to see just how CMake runs the compiler and linker.
I've already tried the following, all to no avail:
1) In my CMakeLists.txt I have put the following line:
set(CMAKE_VERBOSE_MAKEFILE on)
Didn't have any effect.
2) I have started the build like this:
./gradlew build --info
Gradle printed some stuff, but no compiler calls.
3) And like this:
./gradlew build --debug
Gradle printed lots of stuff, but no compiler calls.
So none of those three attempts did what I wanted which makes me wonder how can I see how CMake runs clang on my individual source files?
Disclaimer: the following description applies to the version of Android Gradle Plugin (AGP) that was the latest at the time I updated this Answer (aug '21). If you are curious, have a look at the history of edits.
As #artyomd has noticed, for AGP 4.2.0 and higher, you can set android.native.buildOutput gradle property to verbose to force cmake logging.
In Android Studio, gradle creates directory .cxx under the module root, for each module that has NDK integration, via CMake or ndk-build.
For CMake, the gradle plugin is quite verbose. For each build variant it creates separate subdirectory, e.g. .cxx/cmake/debug/x86 or .cxx/cmake/release/armeabi-v7a, etc.
Each directory contains some useful files: cmake_build_command.txt describes the actual parameters passed to CMake; android_gradle_build.json shows what parameters the gradle plugin derived for your binaries; from build.ninja you can deduce the how these parameters were applied for each compilation or linkage step.
For ndk-build, the android_gradle_build.json file is also quite useful. ndkBuild_build_command.txt lists all parameters passed to ndk-build command, and ndkBuild_build_output.txt is the unabridged output of that command. You can easily add V=1 to the arguments, e.g.
externalNativeBuild {
ndkBuild {
cppFlags "-std=c++11"
arguments "APP_STL=c++_static", "APP_OPTIM=release", "NDK_DEBUG=0", "V=1"
abiFilters "armeabi-v7a"
}
}
For CMake, the relevant argument is "-DCMAKE_VERBOSE_MAKEFILE=ON" (see explanation
and alternatives):
externalNativeBuild {
cmake {
cppFlags "-std=c++11"
arguments "-DCMAKE_VERBOSE_MAKEFILE=ON"
abiFilters "armeabi-v7a"
}
}
But, as #user7860670 has observed, the recent versions of AGP ignore this flag.
Without CMAKE_VERBOSE_MAKEFILE, the Gradle Console displays:
:app:externalNativeBuildDebug
Build native-lib armeabi-v7a
[1/2] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o
[2/2] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so
With "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON", I used to get tons of output:
:app:externalNativeBuildDebug
Build native-lib armeabi-v7a
[1/2] /Users/alex/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=armv5te-none-linux-androideabi --gcc-toolchain=/Users/alex/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64 --sysroot=/Users/alex/Library/Android/sdk/ndk-bundle/platforms/android-14/arch-arm -Dnative_lib_EXPORTS -isystem /Users/alex/Library/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /Users/alex/Library/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -isystem /Users/alex/Library/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -O0 -fno-limit-debug-info -O0 -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -MF CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o.d -o CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -c /Users/alex/test/egl/app/src/main/cpp/native-lib.cpp
[2/2] : && /Users/alex/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=armv5te-none-linux-androideabi --gcc-toolchain=/Users/alex/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64 --sysroot=/Users/alex/Library/Android/sdk/ndk-bundle/platforms/android-14/arch-arm -fPIC -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -O0 -fno-limit-debug-info -O0 -fno-limit-debug-info -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -llog -lEGL -lGLESv2 -lm "/Users/alex/Library/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_static.a" "-latomic" && :
Not anymore. As far as I know, this information is filtered by Gradle Plugin and is completely lost. I can recover it only manually: run the command
/Users/alex/Library/Android/sdk/cmake/3.10.2.4988404/bin/cmake --build app/.cxx/cmake/debug/armeabi-v7a
You can use the Terminal window (Alt-F12) of Android Studio. This will invoke ninja with -v flag when -DCMAKE_VERBOSE_MAKEFILE=ON was used to sync C++ with Gradle.
Note that the expected file .cxx/cmake/debug/armeabi-v7a/cmake_build_output.txt does not contain interesting information (unless you have problems with CMake configuration per se).
P.S. with this 3.6.0 Gradle Plugin, if you have a compilation error, then the whole command line for compiler is shown in Build Output window, no matter whether you set CMAKE_VERBOSE_MAKEFILE or not. Actually, twice: once, in black on white (I don't use the dark theme), second time, in brown on white, after
FAILURE: Build failed with an exception.
* What went wrong:
As an ugly workaround I've replaced ninja with my own executable that passes all the commands to the real ninja executable appending "-v"
Try to update your gradle version.

gcc - How to remove all absolute path from static library output (.a)

I am using GCC for ARM (Red Suite 4 NXP). I am compiling static library files (.a) that are used for a final application. I need to configure the project so any developer can produce the exact same static library output. (This is mainly so a new developer can verify they have their setup correct.) I have two copies of my project (two checkouts from SVN). When I build with each, I notice some absolute path information in the static library .a output files. This means that SVN detects as a change. I'm using the ar -D (deterministic) option already. Are there any other options to remove path information? I tried gcc -s but this didn't work (it appears this is only for final executable, not libraries)
I don't know where/why the absolute paths are in the .a, but I can provide more information if someone can point me in the right direction.
I've looked at the strip utility man pages (haven't tried it yet), would this remove this path information?
Also, I am using Red Suite to manage the project, so I'm trying to do things the Red Suite way (and to let it do its thing). However, if there is a gcc or ar option I need to adjust, I do know how to do that. I just don't know what option to change.
Here is the build console output. This causes the absolute path of my project to be included into the resulting .a. That is what I am trying to fix.
**** Build of configuration Release for project lib_touch ****
make -j all
Building file: C:/Users/my_user_name/Documents/My Project Verification build/src/touch/Touch.c
Building file: C:/Users/my_user_name/Documents/My Project Verification build/src/touch/TouchCalibration.c
Building file: C:/Users/my_user_name/Documents/My Project Verification build/src/touch/TouchPoint.c
Building file: C:/Users/my_user_name/Documents/My Project Verification build/src/touch/TouchEventQueue.c
Invoking: MCU C Compiler
Invoking: MCU C Compiler
arm-none-eabi-gcc -D__REDLIB__ -DNDEBUG -D__CODE_RED -D__USE_CMSIS=CMSISv2p00_LPC177x_8x -I"C:\Users\my_user_name\Documents\My Project Verification build\src\build\RedSuite4NXP\CMSISv2p00_LPC177x_8x\inc" -I../../../../board -I../../../../board/lpc1788 -I../../../../communication -I../../../../events -I../../../../geometry -I../../../../graphics -I../../../../hmilogic/include -I../../../../sound -I../../../../util -O3 -Wall -Werror -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -std=gnu99 -mcpu=cortex-m3 -mthumb -MMD -MP -MF"touch/Touch.d" -MT"touch/Touch.d" -o"touch/Touch.o" "C:/Users/my_user_name/Documents/My Project Verification build/src/touch/Touch.c"
arm-none-eabi-gcc -D__REDLIB__ -DNDEBUG -D__CODE_RED -D__USE_CMSIS=CMSISv2p00_LPC177x_8x -I"C:\Users\my_user_name\Documents\My Project Verification build\src\build\RedSuite4NXP\CMSISv2p00_LPC177x_8x\inc" -I../../../../board -I../../../../board/lpc1788 -I../../../../communication -I../../../../events -I../../../../geometry -I../../../../graphics -I../../../../hmilogic/include -I../../../../sound -I../../../../util -O3 -Wall -Werror -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -std=gnu99 -mcpu=cortex-m3 -mthumb -MMD -MP -MF"touch/TouchCalibration.d" -MT"touch/TouchCalibration.d" -o"touch/TouchCalibration.o" "C:/Users/my_user_name/Documents/My Project Verification build/src/touch/TouchCalibration.c"
Invoking: MCU C Compiler
Invoking: MCU C Compiler
arm-none-eabi-gcc -D__REDLIB__ -DNDEBUG -D__CODE_RED -D__USE_CMSIS=CMSISv2p00_LPC177x_8x -I"C:\Users\my_user_name\Documents\My Project Verification build\src\build\RedSuite4NXP\CMSISv2p00_LPC177x_8x\inc" -I../../../../board -I../../../../board/lpc1788 -I../../../../communication -I../../../../events -I../../../../geometry -I../../../../graphics -I../../../../hmilogic/include -I../../../../sound -I../../../../util -O3 -Wall -Werror -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -std=gnu99 -mcpu=cortex-m3 -mthumb -MMD -MP -MF"touch/TouchEventQueue.d" -MT"touch/TouchEventQueue.d" -o"touch/TouchEventQueue.o" "C:/Users/my_user_name/Documents/My Project Verification build/src/touch/TouchEventQueue.c"
Finished building: C:/Users/my_user_name/Documents/My Project Verification build/src/touch/Touch.c
arm-none-eabi-gcc -D__REDLIB__ -DNDEBUG -D__CODE_RED -D__USE_CMSIS=CMSISv2p00_LPC177x_8x -I"C:\Users\my_user_name\Documents\My Project Verification build\src\build\RedSuite4NXP\CMSISv2p00_LPC177x_8x\inc" -I../../../../board -I../../../../board/lpc1788 -I../../../../communication -I../../../../events -I../../../../geometry -I../../../../graphics -I../../../../hmilogic/include -I../../../../sound -I../../../../util -O3 -Wall -Werror -c -fmessage-length=0 -fno-builtin -ffunction-sections -fdata-sections -std=gnu99 -mcpu=cortex-m3 -mthumb -MMD -MP -MF"touch/TouchPoint.d" -MT"touch/TouchPoint.d" -o"touch/TouchPoint.o" "C:/Users/my_user_name/Documents/My Project Verification build/src/touch/TouchPoint.c"
Finished building: C:/Users/my_user_name/Documents/My Project Verification build/src/touch/TouchEventQueue.c
Finished building: C:/Users/my_user_name/Documents/My Project Verification build/src/touch/TouchCalibration.c
Finished building: C:/Users/my_user_name/Documents/My Project Verification build/src/touch/TouchPoint.c
Building target: lib_touch.a
Invoking: MCU Archiver
arm-none-eabi-ar -rD "lib_touch.a" ./touch/Touch.o ./touch/TouchCalibration.o ./touch/TouchEventQueue.o ./touch/TouchPoint.o
c:\code_red\RedSuiteNXP_4.3.0_1033\redsuite\tools\bin\arm-none-eabi-ar.exe: creating lib_touch.a
Finished building target: lib_touch.a
make --no-print-directory post-build
Performing post-build steps
arm-none-eabi-size "lib_touch.a" ; cp "lib_touch.a" "../../../../lib/lib_touch.a"; # arm-none-eabi-objdump -h -S "lib_touch.a" >"lib_touch.lss"
text data bss dec hex filename
1864 0 156 2020 7e4 Touch.o (ex lib_touch.a)
576 0 0 576 240 TouchCalibration.o (ex lib_touch.a)
320 0 0 320 140 TouchEventQueue.o (ex lib_touch.a)
96 0 0 96 60 TouchPoint.o (ex lib_touch.a)
UPDATE: MORE INFORMATION
I have done some more digging, and it appears the full file path is in front of a string constant. The path data within the .a file shows
C:/Users/my_user_name/Documents/My Project Verification build/src/touch/Touch.c.TouchIdleTimer
I have a string literal "TouchIdleTimer" within the file Touch.c. Is this the cause? How would I remove the path portion, or is it possible? TIA
Update
Via this answer to GCC: static linking only some libraries
Note: If you use full path of a .so file, it will again be linked in dynamically.
Enhanced Static Library Support in Code Red IDE v4: Creating static library projects
Searching around I'm seeing suggestions for -fPIC or -fpic. It was recommended in this comment thread in response to a question similar to yours.
3.2 Shared libraries and static libraries provides a nice breakdown of compiling shared and static libraries.
You stated static not shared libraries but just in case: How to Write Shared Libraries

gcc difference between -pthread and -pthreads?

I have a pthreads program. I have to compile it with gcc -pthread in Linux (-pthreads is unrecognized option) and gcc -pthreads in Sun (-pthread is unrecognized option). Why the difference, since it's the same compiler? However, -lpthread works on both, but I heard this isn't always sufficient.
The Solaris -pthreads and Linux -pthread options do equivalent things. Apparently, gcc-4.x series accepts -pthread for Solaris as well.
You do want the -pthread/-pthreads option while compiling because it adds multithreading support in the preprocessor and the linker.

Resources