Suppose the file contents are as follows:
+main.cpp//source file
+zy_ftdcmdapi.cpp//source file
+zy_ftdcmdapi.h//Header file
TRADERAPI//Sub-folders
++apiheader.h//Header file
++libthostmduserapi.so//Dynamic link library
Then the compilation process is:
g++-o m main.cpp zy_ftdcmdapi.cpp-i./traderapi/-l./traderapi-lthostmduserapi
-i./traderapi/is the path to the header file used in the source code
-L./TRADERAPI is the path to the dynamic link library that is used
-LTHOSTMDUSERAPI is a dynamic link library, note that the dynamic link library itself must be libxxxx.so this notation, compile time omit "Lib" and ". So"
Supplement 1:
When running, it is possible that the executable file m cannot find the dynamic link library and the following error occurs:
./m:error while loading shared libraries:libthostmduserapi.so:cannot open Shared object file:no such file or directory
This is because the program defaults to the/lib64/directory for the dynamic link library, and the thostmduserapi.so used in the program is not in/lib64/. Therefore, you need to add the following command to get the program to the directory of the instruction to find the library
Export Ld_library_path= $LD _library_path:./traderapi
Supplement 2:
If you do not like-lthostmduserapi this writing, or not accustomed to the dynamic Link library lib. Lib can also be removed, directly ctrip xxxx.so just compile, you need to use the dynamic link library as a. cpp file to compile.
Assuming the name of the dynamic-link library is thostmduserapi.so, then compile the command:
and this method does not occur in the "Record 1" issue . Pretty good.
How Linux g++ uses dynamic-link libraries