Unless explicitly stated, this article only for X86/X86_64 Linux development environment, a friend said Baidu not to, open a paste record (bold font is the key word):
Use "-wl,-bstatic" to specify a linked static library, use "-wl,-bdynamic" to specify a link shared library, using the example:
-wl,-bstatic-lmysqlclient_r-lssl-lcrypto-wl,-bdynamic-lrt-wl,-bdynamic-pthread-wl,-bstatic-lgtest
(The "-WL" representation is a parameter passed to the linker LD, not a compiler gcc/g++ parameter.) )
1) The following is because no link parameters are specified-lz (/USR/LIB/LIBZ.SO,/USR/LIB/LIBZ.A)
/USR/LOCAL/MYSQL/LIB/MYSQL/LIBMYSQLCLIENT.A (MY_COMPRESS.C.O): in function ' my_uncompress ':
/home/software/mysql-5.5.24/mysys/my_compress.c:122:undefined reference to ' uncompress '
/USR/LOCAL/MYSQL/LIB/MYSQL/LIBMYSQLCLIENT.A (MY_COMPRESS.C.O): in function ' My_compress_alloc ':
/home/software/mysql-5.5.24/mysys/my_compress.c:71:undefined reference to ' compress '
2) The following is because the compilation link parameter-pthread is not specified (note that not only-lpthraed)
/USR/LOCAL/MYSQL/LIB/MYSQL/LIBMYSQLCLIENT.A (CHARSET.C.O): in function ' Get_charset_name ':
/home/zhangsan/mysql-5.5.24/mysys/charset.c:533:undefined reference to ' pthread_once '
3 The following is because the link parameter is not specified-LRT
/USR/LOCAL/THIRDPARTY/CURL/LIB/LIBCURL.A (LIBCURL_LA-TIMEVAL.O): in function ' Curlx_tvnow ':
TIMEVAL.C: (. text+0xe9): Undefined reference to ' clock_gettime '
4 The following is because the link parameter is not specified-LDL
/USR/LOCAL/THIRDPARTY/OPENSSL/LIB/LIBCRYPTO.A (DSO_DLFCN.O): in function ' Dlfcn_globallookup ':
DSO_DLFCN.C: (. text+0x4c): Undefined reference to ' Dlopen '
DSO_DLFCN.C: (. text+0x62): Undefined reference to ' Dlsym '
DSO_DLFCN.C: (. text+0x6c): Undefined reference to ' dlclose '
5 below this is because the link parameter-static is specified, it exists, requires that the link must be a static library, not a shared library
ld:attempted static link of dynamic object
If specified in the-L-l mode, the. A file must exist under the directory, otherwise a library file of-L cannot be found: Ld:cannot find-lace
6 The GCC compilation encountered the following error, possibly because at compile time did not specify-fpic, remember:-fpic is the compilation parameter, is also the link parameter
Relocation r_x86_64_32s against ' vtable for CMyClass ' can is used when making a shared object
7 The following error indicates that GCC compile-time needs to define macro __stdc_format_macros and must include header files Inttypes.h
Test.cpp:35:error:expected ') ' Before ' PRIu64 '
8) The following is because compilation parameters are not specified on the x86 machine (32-bit)-MARCH=PENTIUM4
.. /.. /src/common/libmooon.a (LOGGER.O): in function ' atomic_dec_and_test ':
.. /.. /include/mooon/sys/atomic_gcc.h:103:undefined reference to ' __sync_sub_and_fetch_4 '
9 The following error may be due to an extra "}"
error:expected declaration before '} ' token
10 The following error may be due to a missing "}"
Error:expected '} ' at end of input
11 The following error is when compiling a shared library, the shared library relies on a static library compiled without the "-fpic" parameter, the workaround is to recompile the dependent static library with "-fpic"
Relocation r_x86_64_32 against ' a local symbol ' can is used when making a shared object; Recompile with-fpic
12 The following error is due to improper use of "_syscall0 (pid_t, Gettid)" in header file
./test.o:in function ' Gettid () ':
./test.h:17:multiple definition of ' gettid () '
The correct usage is to use "inline" or "static inline" to modify:
Inline _syscall0 (pid_t, Gettid)
Or
Static inline _syscall0 (pid_t, Gettid)
Of course, you can do this:
In the. h header file: extern "C" pid_t gettid (void);
In the. cpp file: _syscall0 (pid_t, Gettid)
_syscall0 is a macro that defines the implementation of a function.
13 The following compile alarm is because a static type of function is not used
my.cpp:364:warning: ' int my_function (const cgicc::cgicc&, const std::string&) ' defined but not used
Simply use the declaration of the "__attribute__ (unused)" modifier function:
static int __attribute__ ((unused)) my_function (const cgicc::cgicc&, const std::string&);
14 The following error (thrift-0.9.0 and thrift-0.9.1 encountered) was encountered when performing thrift configure:
Checking for setsockopt in-lsocket ... no
Checking for Bn_init in-lcrypto ... no
Configure:error: "Error:libcrypto required."
The reason may be that the--prefix, such as--PREFIX=/USR/LOCAL/THIRDPARTY/OPENSSL, is specified when compiling the installation OpenSSL:
The--with-openssl=/usr/local/thirdparty/openssl of the Configure, which does not designate thrift, is replaced by:
cppflags= "-i/usr/local/thirdparty/openssl/include" ldflags= "-ldl-l/usr/local/thirdparty/openssl/lib"
It's OK to replace it.
15 The following compile error (shown as g++ into the dead loop) may be caused by a lack of a closing brace "}", such as a less "}" when defining namespaces:
/usr/include/c++/4.1.2/tr1/type_traits:408:error: ' size_t ' is not a ' db_proxy::std '
/usr/include/c++/4.1.2/tr1/type_traits:408:error: ' size_t ' is not a ' db_proxy::std '
/usr/include/c++/4.1.2/tr1/mu_iterate.h:49:error: ' STD::TR1 ' has not been declared
/usr/include/c++/4.1.2/tr1/mu_iterate.h:49:error: ' STD::TR1 ' has not been declared
/usr/include/c++/4.1.2/tr1/bind_iterate.h:78:error: ' STD::TR1 ' has not been declared
/usr/include/c++/4.1.2/tr1/bind_iterate.h:78:error: ' STD::TR1 ' has not been declared
/usr/include/c++/4.1.2/tr1/bind_iterate.h:78:error: ' STD::TR1 ' has not been declared
PROTOC compilation error, the following error is not performed in the directory where the. proto file is located:
/tmp/test.proto:file does not reside within the any path specified using--proto_path (or-i). You are must specify a--proto_path which encompasses this file. Note This proto_path must be a exact prefix of the. proto file names--Protoc is too dumb to figure out when two pat HS (e.g. absolute and relative) are equivalent (it s harder than you).
There are two solutions: one is to execute the PROTOC in the directory where the. proto file is located, and the second is to specify the parameter--proto_path for PROTOC, which is the directory of the. proto file.
17 The following compilation error may be due to the invocation of a member function of a class object within the global domain that cannot be directly executed in the global domain:
Error:expected constructor, destructor, or type conversion before '-> ' token
18 The following error is due to the absence of a link OpenSSL libcrypto library, or the use of a static library, and the order is not:
Undefined symbol:evp_enc_null
19 The following is a link error, not a compile error, plus "-pthread" can be, attention is not "-lpthread":
/USR/LOCAL/MYSQL/LIB/MYSQL/LIBMYSQLCLIENT.A (CHARSET.C.O): in function ' Get_charset_name ':
/home/software/mysql-5.5.24/mysys/charset.c:533:undefined reference to ' pthread_once '
/USR/LOCAL/MYSQL/LIB/MYSQL/LIBMYSQLCLIENT.A (CHARSET.C.O): in function ' Get_charset_number ':
20 depending on the OpenSSL (assuming installed in/usr/local/thirdparty/openssl-1.0.2a), if
./configure--prefix=/usr/local/thirdparty/libssh2-1.6.0--with-libssl-prefix=/usr/local/thirdparty/ openssl-1.0.2a
You encounter the following error:
Configure:error:No Crypto Library found!
Try--with-libssl-prefix=path
or--with-libgcrypt-prefix=path
or--with-wincng on Windows
You can resolve the following methods:
./configure--prefix=/usr/local/thirdparty/libssh2-1.6.0--with-openssl cppflags= "-I/usr/local/thirdparty/ Openssl-1.0.2a/include "ldflags="-l/usr/local/thirdparty/openssl-1.0.2a/lib "
21) The error "error:expected primary-expression before '; ' token" may be due to the following reasons:
userinfointernal* user_info_internal = new Userinfointernal;
Delete User_info; This should be user_info_internal.
22 The reason for this compilation error is that there are no double quotes when defining a String macro:
Example.cpp:563:16:error:too many decimal points in number
If the definition becomes: #define IP1 127.0.0.1, change to #define IP1 "127.0.0.1" after the problem is solved.
23 The following compilation error is because the g++ command parameter is not written right, there is a "-"
g++:-e or-x required when input
Such as:
Cppflags=-pthread-
g++-g-o $@ $^ $ (cppflags) $ (ldflags)
) libjson_7.6.1 Compilation Error:
makefile:180:extraneous text after ' else ' directive
makefile:183: * * Only one ' else ' conditional. Stop.
Solution:
Locate line 180th of the makefile file, and change "Else ifeq ($ (build_type), Debug)" to two lines inline:
# Build_type specific settings
Ifeq ($ (build_type), small)
Cxxflags = $ (Cxxflags_small)
Else
Ifeq ($ (build_type), Debug) # cannot be on the same line as else, otherwise makefile syntax error does not support else ifeq
Cxxflags = $ (cxxflags_debug)
Libname: = $ (Libname_debug)
Else
Cxxflags? = $ (Cxxflags_default)
endif
endif
You can set the Build_type by setting the environment variable, such as: Export Build_type=debug
You can also set the installation directory for make install by using environment variables, such as: Export Prefix=/usr/local/libjson
Related Small Knowledge:
In the makefile file, PREFIX=/USR and prefix?=/usr are different, the former assignment cannot be overridden by an environment variable, and the latter can be overridden with the value of an environment variable.
Also, delete line No. 271:
CP-RV $ (Srcdir)/dependencies/$ (include_path)/$ (LIBNAME_HDR)/$ (Srcdir)
Change into:
CP-RV _internal/dependencies/$ (include_path)/$ (LIBNAME_HDR)/$ (Srcdir)
There is also a line before the No. 258 insert a command:
Mkdir-p $ (Inst_path)
Otherwise "cp-f./$ (lib_target) $ (Inst_path)", Lib will be the library filename.
25 when compiling GCC, if you encounter the following error, this is because the runtime can not find the MPC, MPFR and GMP so file:
Checking for x86_64-unknown-linux-gnu-nm .../data/gcc-4.8.2_src/host-x86_64-unknown-linux-gnu/gcc/nm
Checking for x86_64-unknown-linux-gnu-ranlib ... ranlib
Checking for X86_64-unknown-linux-gnu-strip ... strip
Checking whether Ln-s works ... yes
Checking for X86_64-UNKNOWN-LINUX-GNU-GCC .../data/gcc-4.8.2_src/host-x86_64-unknown-linux-gnu/gcc/xgcc-b/data/ gcc-4.8.2_src/host-x86_64-unknown-linux-gnu/gcc/-b/data/gcc-4.8.2/x86_64-unknown-linux-gnu/bin/-B/data/ gcc-4.8.2/x86_64-unknown-linux-gnu/lib/-isystem/data/gcc-4.8.2/x86_64-unknown-linux-gnu/include-isystem/data/ Gcc-4.8.2/x86_64-unknown-linux-gnu/sys-include
Checking for suffix of object files ... configure:error:in '/DATA/GCC-4.8.2_SRC/X86_64-UNKNOWN-LINUX-GNU/LIBGCC ':
Configure:error:cannot compute suffix of object Files:cannot compile
"Config.log ' for more details."
MAKE[2]: * * * [CONFIGURE-STAGE1-TARGET-LIBGCC] Error 1
So you just need to do the following:
Export Ld_library_path=/usr/local/mpc/lib:/usr/local/mpfr/lib:/usr/local/gmp/lib: $LD _library_path
Note: gcc-4.8.2 relies on MPC, MPFR and GMP:
./configure--prefix=/usr/local/gcc-4.8.2--with-mpc=/usr/local/mpc-1.0.3--with-mpfr=/usr/local/mpfr-3.1.3-- with-gmp=/usr/local/gmp-6.0.0
And the MPC relies on: MPFR and GMP:
./configure--prefix=/usr/local/mpc-1.0.3--with-mpfr=/usr/local/mpfr-3.1.3--with-gmp=/usr/local/gmp-6.0.0
26 When compiling GCC, if you encounter the following error:
Fatal error:gnu/stubs-32.h:no such file or directory
This is because on x86_64, the default is to compile 32-bit and 64-bit two versions. When you compile 32-bit, you need 32-bit LIBC header files and library files on the machine, but some machines may not, such as no/lib directories, only/lib64 directories, which means that 32-bit libc is not supported. To solve this problem, you can prevent the compilation of 32-bit versions,--disable-multilib with parameters on configure, or install a 32-bit version of GLIBC.
27 A compile encountered a link error such as the following:
redis_dbi.cpp:224:undefined reference to ' Sdscatlen (char*, void const*, unsigned long) '
By common sense, this error is either not specifying the corresponding library or the order problem between the static libraries.
But after checking, these two reasons, but because GCC and g++ mixed reason:
1. The library LIBHIREDIS.A and libhiredis.so are compiled by GCC
2. The code that invoked it was compiled by g++, causing the problem.
There are two solutions to the problem:
1. Modify the. h file where the Sdscatlen is located and use the code
#ifdef __cplusplus
extern "C" {
#endif
Decorated, or directly using the "extern C" modifier function Sdscatlen.
2. Do not modify Redis code, add "extern" C "{" When referencing Sds.h:
extern "C" {
#include "Sds.h"
}
Both of these options are available, and of course you can consider using g++ to compile Redis, but you may encounter many errors.
Redis External Direct use of the header file hiredis.h has used extern "C" {, so there is no problem, only if you skip hiredis.h, to use some internal header files need to pay attention.
x.hpp:27:error:expected identifier before string constant
X.hpp:27:error:expected '} ' before string constant
x.hpp:27:error:expected Unqualified-id before string constant
This error may be a string macro with the same name as the existence and enumeration, such as the following macro definition:
Enum DBTYPE
{
undefine = 0,
mysql_db = 1,
oracle_db = 2
};
Macros are defined in another. h file:
#define MYSQL_DB "MYSQL"
29 The following error is because the declaration of the class member function and the return value of the definition are not the same
Test.cpp:201:6: Error: ' bool foo (const string&, const string&, const string&, const string& ;, const hbaserowvalue&) ' prototype does not match any of the class ' CTest '
BOOL Chbaseoper::foo (const std::string& tablename, const std::string& rowkey, const std::string& familyname , const std::string& columnname, const std::string& columnvalue, const hbaserowvalue& row_values)
^
In the file included from test.cpp:8:0:
Test.h:58:6: Error: Optional: int foo (const string&, const string&, const string&, const string& , const hbaserowvalue&)
int foo (const std::string& tablename, const std::string& rowkey, const std::string& familyname, const STD::ST ring& columnname, const std::string& columnvalue, const hbaserowvalue& row_values);
30)
Messenger.cpp:5: error:expected unqualified-id before ': ' token
The reason for this compilation error is:
Cmessager:cmessager ()
{
}
That is, a colon is missing:
Cmessager::cmessager ()
{
}
Unable to find a register to spill in class ' Sireg '
If you encounter this error at compile time, the easiest way to get rid of a GCC bug is to remove the optimizations such as-o3 in the compilation parameters, and then try to be successful, or consider specifying-FNO-SCHEDULE-INSNS.
32 like the following such a large pile of errors, you can consider whether the "}" and so caused by
/USR/INCLUDE/C++/4.8.2/BITS/STL_LIST.H:131:15: Error: ' Bidirectional_iterator_tag ' is not a type name in namespace ' TOM::STD '
typedef std::bidirectional_iterator_tag Iterator_category;
^
/usr/include/c++/4.8.2/bits/stl_list.h: In the member function ' _tp* tom::std::_list_iterator<_tp>::operator-> () const ':
/usr/include/c++/4.8.2/bits/stl_list.h:150:16: Error: ' __addressof ' is not a member of ' TOM::STD '
{return std::__addressof (static_cast<_node*> (_m_node)->_m_data);}
Like what:
Namespace A {namespace B {
。。。。。。
There's One Less "}"
}//Namespace A {namespace B {
Crc32 ' cannot be used as a function
uint32_t CRC32 = CRC32 (0L, (const unsigned char*) crc32_str.data (), crc32_str.size ());
The error is because the function name and variable name are the same and can be resolved as follows:
uint32_t CRC32 =:: Crc32 (0L, (const unsigned char*) crc32_str.data (), crc32_str.size ());
34)
/data/x/mooon/tools/hbase_stress.cpp:in function ' void test_write (const STD::MAP<STD::BASIC_STRING<CHAR> Std::basic_string<char> >&) ':
/data/x/mooon/tools/hbase_stress.cpp:78:117:error:invalid conversion from ' void (*) (uint8_t, const string& uint16_t) {aka Void (*) (unsigned char, const std::basic_string<char>&, short unsigned int)} ' to ' Mooon::sys::fu nctionwith3parameter<unsigned Char, std::basic_string<char>, short unsigned int>::functionptr {aka void (* (unsigned char, STD::BASIC_STRING<CHAR>, short unsigned int)} ' [-fpermissive]
Stress_threads[i] = new Mooon::sys::cthreadengine (Mooon::sys::bind (Write_thread, I, Hbase_ip, Hbase_port)); ^
In file included from/data/x/mooon/tools/hbase_stress.cpp:24:0:
/data/x/mooon/tools/.. /include/mooon/sys/thread_engine.h:777:16:error:initializing argument 1 of ' Mooon::sys::functor mooon::sys::bind ( TypeName Mooon::sys::functionwith3parameter<parameter1type, Parameter2type, Parameter3type>::functionptr, Parameter1type, Parameter2type, Parameter3type) [With parameter1type = unsigned char; Parameter2type = std::basic_string<char>; Parameter3type = short unsigned int; TypeName Mooon::sys::functionwith3parameter<parameter1type, parameter2type, parameter3type>::functionptr = void (*) (unsigned char, STD::BASIC_STRING<CHAR>, short unsigned int)] ' [-fpermissive]
Inline functor Bind (TypeName Functionwith3parameter<parameter1type, Parameter2type, Parameter3type>:: FunctionPtr function_ptr, Parameter1type parameter1, Parameter2type, Parameter2 Parameter3type)
The above error means that the first argument is of type
void (*) (unsigned char, std::basic_string<char>, short unsigned int)
But the incoming type is
void (*) (unsigned char, const std::basic_string<char>&, short unsigned int)
As you can see from the above comparison, the second parameter of the function is required to be the std::string type, not the const std::string& type.
) Conflicting declaration
has a previous declaration as
This error may be due to the fact that the header file is not #ifndef, causing multiple introductions.
Warning:cannot Pass objects of non-pod type ' const struct Std::basic_string<char, Std::char_traits<char> d::allocator<char> > ' through ' ... '; Call to abort at runtime
Warning:format '%s ' expects type ' char* ', but argument 3 has type ' int
This error is because the value of the format%s parameter is a std::string value, which may trigger sigill (illegal instruction) at run time, for example:
std::string type;
std::string name;
。。。 。。。
Const std::string& key = Mooon::utils::cstringutils::format_string ("%s_%s", Type.c_str (), name);
Notoginseng) ' __curl_rule_01__ ' is negative
This compilation error is due to compiling 64-bit programs on 64-bit platforms, but the Curl Library is compiled in 32-bit ways.
COUNTABLE_LOG_WRITER.CPP:54:50: Error: Invalid conversion from type ' const ccounter* ' to type ' ccounter* ' [-fpermissive]
return (NULL = = counter)? &_default_counter:counter;
^
The error actually occurs on the use of _default_counter, and returns the ccounter* of the non-const type.
And since the function get_counter is a const type function, it means that this is also a const type,
&_default_counter also became the const ccounter* type.
A simple modification is to define _default_counter as ccounter* pointer type, not Ccounter object type.
ccounter* ccountablelogwriter::get_counter (const std::string& type) const
{
ccounter* counter = NULL;
Ccountertable::const_iterator iter = _counter_table.find (type);
if (ITER!= _counter_table.end ())
Counter = iter->second;
return (NULL = = counter)? &_default_counter:counter;
}