What is the difference between gcc -pthread
and gcc -lpthread
which is used while compiling multithreaded programs?
相关问题
- How to let a thread communicate with another activ
- Why it isn't advised to call the release() met
- ThreadPoolTaskScheduler behaviour when pool is ful
- Error building gcc 4.8.3 from source: libstdc++.so
- Custom TaskScheduler, SynchronizationContext?
相关文章
- Difference between Thread#run and Thread#wakeup?
- Java/Spring MVC: provide request context to child
- Threading in C# , value types and reference types
- RMI Threads prevent JVM from exiting after main()
- gcc/g++ gives me error “CreateProcess: No such fil
- Calls that precede a function's definition can
- How can I use gcc's -I command to add recursiv
- How do I know if std::map insert succeeded or fail
-pthread
Adds support for multithreading with the pthreads library. This option sets flags for both the preprocessor and linker (man gcc
).while
-lpthread
comes in existence while linking there will be no influence while preprocessing.-pthread
tells the compiler to link in the pthread library as well as configure the compilation for threads.For example, the following shows the macros that get defined when the
-pthread
option gets used on the GCC package installed on my Ubuntu machine:Using the
-lpthread
option only causes the pthread library to be linked - the pre-defined macros don't get defined.Bottom line: you should use the
-pthread
option.Note: the
-pthread
option is documented as a platform specific option in the GCC docs, so it might not always be available. However, it is available on platforms that the GCC docs don't explicitly list it for (such as i386 and x86-64) - you should use it when available.Also note that other similar options have been used by GCC, such as
-pthreads
(listed as a synonym for-pthread
on Solaris 2) and-mthread
(for MinGW-specific thread support on i386 and x86-64 Windows). My understanding is that GCC is trying to move to using-pthread
uniformly going forward.