Compile, call, and debug poco 1.6.0 in linux, cmake1.6.0

Source: Internet
Author: User

Compile, call, and debug poco 1.6.0 in linux, cmake1.6.0

I noted down in the previous article:

Notes about Poco: TCPServer framework (the select model is used in windows.

Http://www.cnblogs.com/bleachli/p/4352959.html

Here, I will continue to learn how to use cmake to compile poco in linux.

 

 

An error occurred while compiling the document.

From the README file of poco, we can see that:

"

Building on unix/LINUX/MAC OS X
====================================

For building on Unix platforms, the poco c ++ Libraries come with their own
Build system. The build system is based on GNU Make 3.80 (or newer), with the help
From a few shell scripts. If you do not have GNU Make 3.80 (or later) installed on
Your machine, you will need to download it from
Http://directory.fsf.org/devel/build/make.html>,
Build and install it prior to building the poco c ++ Libraries.

You can check the version of GNU Make installed on your system

> Gmake -- version

Or

> Make -- version

Once you have GNU Make up and running, the rest is quite simple.
To extract the sources and build all libraries, testsuites and samples, simply

> Gunzip poco-X.Y.tar.gz
> Tar-xf poco-X.Y.tar
> Cd poco-X.Y
>./Configure
> Gmake-s

"

But I always think cmake is relatively simple, so use cmake to compile. The official website will have two commands:

"

Cmake.

Make

"

 

An error occurs when poco is compiled according to the instructions on the official website.

Http://pocoproject.org/docs/00200-GettingStarted.html

Building On Unix/Linux/Mac OS X

Possible errors:

1. error, cmake_minimum_required (VERSION 3.0.0)

The minimum cmake version must be later than 3.0.0.

 

2. Error make [2]: *** No rule to make target 'lib/libPocoFoundation. so.1 (2014-12-22 ). 6 ). 0 (2014-12-22) ', needed by 'lib/libPocoXML. so.30 '. stop.
Make [1]: *** [XML/CMakeFiles/XML. dir/all] Error 2
Make: *** [all] Error 2

Poco/version File

1.6.0 ()-> the generated so file has a problem and cannot be called.

 

Change

1.6.0

 

Otherwise, the generated so name contains spaces, and the file cannot be correctly generated.

Generate the poco so Library

Run in poco

Cmake.

Make

You will see:

[ 34%] Built target Foundation[ 47%] Built target XML[ 49%] Built target JSON[ 68%] Built target Net[ 72%] Built target MongoDB[ 77%] Built target Util[ 79%] Built target Crypto[ 84%] Built target NetSSL[ 91%] Built target Data[ 92%] Built target DataSQLite[ 94%] Built target DataMySQL[ 99%] Built target Zip[100%] Built target PageCompiler[100%] Built target File2Page

 

 

Use poco Library

This is what we need.

So how to use it.

Previously mentioned

Notes about Poco: TCPServer framework (the select model is used in windows.

Http://www.cnblogs.com/bleachli/p/4352959.html

TimeServer. cpp works in

... \ Poco-1.6.0-all \ Net \ samples \ TimeServer

Check the cmakelists.txt file in the TimeServer directory.

set(SAMPLE_NAME "TimeServer")set(LOCAL_SRCS "")aux_source_directory(src LOCAL_SRCS)add_executable( ${SAMPLE_NAME} ${LOCAL_SRCS} )target_link_libraries( ${SAMPLE_NAME} PocoNet PocoUtil PocoJSON PocoXML PocoFoundation )

But this cannot be compiled. It will be reported that the include header file is missing and the so file cannot be found.

Error message:

[root@localhost TimeServer]# /home/cmake-3.1.3-Linux-i386/bin/cmake  .CMake Warning (dev) in CMakeLists.txt:  No cmake_minimum_required command is present.  A line of code such as    cmake_minimum_required(VERSION 3.1)  should be added at the top of the file.  The version specified may be lower  if you wish to support older CMake versions for this project.  For more  information run "cmake --help-policy CMP0000".This warning is for project developers.  Use -Wno-dev to suppress it.-- Configuring done-- Generating done-- Build files have been written to: /home/poco-1.6.0-all/Net/samples/TimeServer[root@localhost TimeServer]# makeScanning dependencies of target TimeServer[100%] Building CXX object CMakeFiles/TimeServer.dir/src/TimeServer.o/home/poco-1.6.0-all/Net/samples/TimeServer/src/TimeServer.cpp:15:32: fatal error: Poco/Net/TCPServer.h: No such file or directorycompilation terminated.make[2]: *** [CMakeFiles/TimeServer.dir/src/TimeServer.o] Error 1make[1]: *** [CMakeFiles/TimeServer.dir/all] Error 2make: *** [all] Error 2[root@localhost TimeServer]# 

 

So change it.

# Define the minimum version. cmake_minimum_required (VERSION 3.0.0) # set (SAMPLE_NAME "TimeServer") PROJECT ($ {SAMPLE_NAME}) # define the PROJECT name SET (CMAKE_BUILE_TYPE DEBUG) # specify the compilation type to set the compilation type debug or release. Debug generates debugging information. You can use GDB for debugging.

# SET (CMAKE_CXX_FLAGS_DEBUG "$ ENV {CXXFLAGS}-O0-Wall-g-ggdb ")

# SET (CMAKE_CXX_FLAGS_RELEASE "$ ENV {CXXFLAGS}-O3-Wall ")

# ADD_SUBDIRECTORY (utility) # Add the subdirectory to be compiled as the subdirectory for storing source code in the main directory of the project. Use this command to display subdirectories in random order. # Set (path_root_dir "/home/poco-1.6.0-all") # Add the header file search path include_directories ($ {path_root_dir}/Net/include) include_directories ($ {path_root_dir}/Util/include) include_directories ($ {path_root_dir}/JSON/include) include_directories ($ {path_root_dir}/XML/include) include_directories ($ {path_root_dir}/Foundation/include) # include_directories ($ {path_root_dir} lib/) # Add a non-standard shared library search path LINK_DIRECTORIES ($ {path_root_dir}/li B/) set (CMAKE_LIBRARY_OUTPUT_DIRECTORY $ {path_root_dir}/lib) set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY $ {path_root_dir}/lib) # Windows DLLs are "runtime" for CMake. output them to "bin" like the Visual Studio projects do. set (CMAKE_RUNTIME_OUTPUT_DIRECTORY $ {path_root_dir}/bin) # SET the output position of the program exe # set (EXECUTABLE_OUTPUT_PATH $ {path_root_dir}/bin) MESSAGE (STATUS "t1 This is SOURCE dir $ {path_root_dir}/Net") MESSAGE (STAT US "t1 This is SOURCE dir $ {path_root_dir}/bin") # set (LOCAL_SRCS "") # aux_source_directory is used to discover all source code files in a directory and store the list in a variable. This command is temporarily used to # automatically build the source file list. Currently, cmake cannot automatically find the newly added source file. Aux_source_directory (src LOCAL_SRCS) # generate the value of add_executable ($ {SAMPLE_NAME }$ {LOCAL_SRCS}) whose exe name is $ {SAMPLE_NAME }) # This command can be used to add the shared library target_link_libraries ($ {SAMPLE_NAME} PocoNet PocoUtil PocoJSON PocoXML PocoFoundation) to the target)

 

Run again:

[root@localhost TimeServer]# /home/cmake-3.1.3-Linux-i386/bin/cmake  .-- t1 This is SOURCE dir /home/poco-1.6.0-all/Net-- t1 This is SOURCE dir /home/poco-1.6.0-all/bin-- Configuring done-- Generating done-- Build files have been written to: /home/poco-1.6.0-all/Net/samples/TimeServer[root@localhost TimeServer]# make-- t1 This is SOURCE dir /home/poco-1.6.0-all/Net-- t1 This is SOURCE dir /home/poco-1.6.0-all/bin-- Configuring done-- Generating done-- Build files have been written to: /home/poco-1.6.0-all/Net/samples/TimeServer[100%] Built target TimeServer[root@localhost TimeServer]# ^C[root@localhost TimeServer]# 

Generate the TimeServer program.

 

 

 

[root@localhost ~]# netstat  -nlap | grep Timetcp        0      0 0.0.0.0:9911            0.0.0.0:*               LISTEN      29518/./TimeServer  
Use gdb to debug TimeServer

Many of the content about debugging cannot be debugged online.

For details about how to use gdb, refer:

Http://blog.csdn.net/bobocheng1231/article/details/2513741

[Root @ localhost bin] # gdb TimeServer
GNU gdb (GDB) Fedora (7.5.0.20120926-25. fc6)
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3 +: gnu gpl version 3 or later This is free software: you are free to change and redistribute it.
There is no warranty, to the extent permitted by law. Type "show copying"
And "show warranty" for details.
This GDB was configured as "i686-redhat-linux-gnu ".
For bug reporting instructions, please see:
<Http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from/home/poco-1.6.0-all/bin/TimeServer... (no debugging symbols found)... done.
(Gdb) info B
No breakpoints or watchpoints.

# Set breakpoints
(Gdb) B TimeServerConnection: run
Breakpoint 1 at 0x804be43

# Run
(Gdb) r
Starting program:/home/poco-1.6.0-all/bin/TimeServer
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/libthread_db.so.1 ".
[New Thread 0xb7babb40 (LWP 17365)]
[New Thread 0xb73aab40 (LWP 17366)]
[New Thread 0xb6ba9b40 (LWP 17367)]
[Switching to Thread 0xb7babb40 (LWP 17365)]

Breakpoint 1, 0x0804be43 in TimeServerConnection: run ()()
Missing separate debuginfos, use: debuginfo-install glibc-2.16-24.fc18.i686 libgcc-4.7.2-8.fc18.i686 libstdc ++-4.7.2-8. fc18.i686

# Display information
(Gdb) l
1 <built-in>: No such file or directory.
(Gdb) l
1 in <built-in>
(Gdb)

The result cannot be displayed.

Long-winded. google solves the problem.

Original article:

Http://www.cmake.org/pipermail/cmake/2012-September/052071.html

Stupid, stupid me. Yes it works, I just ran GDB with "start" instead of "run".Thanks for your help Nils.ChrisOn 2012/09/19 04:56 PM, Nils Gladitz wrote:> "cmake -DCMAKE_BUILD_TYPE=Debug" should be enough to get gdb > debuggable binaries.> Is the process which you intend to debug running when you ask gdb for > a backtrace?> You will only be able to get a backtrace if the process has been > started and has not yet exited.>> e.g.:> gdb ./mybin> break main> run> backtrace>> Nils>> On 09/19/2012 04:43 PM, GOO Creations wrote:>> Hi,>>>> I'm trying to debug my program using GDB. I've done the following:>>>> -DCMAKE_BUILD_TYPE=Debug>> SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -g")>> SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")>>>> But whenever I run GDB and do a backtrace, I get a message: "No Stack".>> I've done a Google search and apparently the -g flag is never passed >> to g++.>> Is -g automatically added when my build type is "Debug"? Does anyone >> know why GDB gives me this error?>>>> Thanks>> Chris>> -- >>>> Powered by www.kitware.com

Use start instead of run Command.

Try again

[Root @ localhost bin] # gdb TimeServer GNU gdb (GDB) Fedora (7.5.0.20120926-25. fc6) Copyright (C) 2012 Free Software Foundation, Inc. license GPLv3 +: gnu gpl version 3 or later # Set the breakpoint (gdb) B TimeServerConnection: runBreakpoint 1 at 0x804be43
# Checkpoint information (gdb) info bNum Type Disp Enb Address What1 breakpoint keep y 0x0804be43 <TimeServerConnection: run () + 5>
# View source code
(Gdb) lNo symbol table is loaded. Use the "file" command.
# Start(Gdb) startTemporary breakpoint 2 at 0x804b924Starting program:/home/poco-1.6.0-all/bin/TimeServer [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/libthread_db.so.1 ". temporary breakpoint 2, 0x0804b924 in main () Missing separate debuginfos, use: debuginfo-install glibc-2.16-24.fc18.i686 libgcc-4.7.2-8.fc18.i686 libstdc ++-4.7.2-8. fc18.i686 (gdb) l1 // 2 // TextConverter. cpp3 // 4 // $ Id: // poco/1.4/Foundation/src/TextConverter. cpp #1 $5 // 6 // Library: Foundation7 // Package: Text8 // Module: TextConverter9 // 10 // Copyright (c) 2004-2006, applied Informatics Software Engineering GmbH. (gdb) cContinuing. [New Thread 0xb7babb40 (LWP 17405)] [New Thread 0xb73aab40 (LWP 17406)] [New Thread 0xb6ba9b40 (LWP 17407)] [Switching to Thread 0xb7babb40 (LWP 17405)] Breakpoint 1, 0x0804be43 in TimeServerConnection: run ()()
# Source code ..... (gdb) l11 // and Contributors.12 // 13 // SPDX-License-Identifier: BSL-1.014 // 151617 # include "Poco/TextConverter. h "18 # include" Poco/TextIterator. h "19 # include" Poco/TextEncoding. h "20 (gdb) nSingle stepping until exit from function _ ZN20TimeServerConnection3runEv, which has no line number information. request from 192.168.10.220: 13986 Poco: Net: TCPServerConnection: start (this = 0xb6000468) at/home/poco-1.6.0-all/Net/src/TCPServerConnection. cpp: 5959} (gdb) l54} 55 catch (...) 56 {57 ErrorHandler: handle (); 58} 59} 606162} // namespace Poco: Net (gdb) nPoco: Net: TCPServerDispatcher :: run (this = 0x8066308) at/home/poco-1.6.0-all/Net/src/TCPServerDispatcher. cpp: 117117 endConnection (); (gdb) l112 {113 std: auto_ptr <TCPServerConnection> pConnection (_ pConnectionFactory-> createConnection (pCNf-> socket ())); 114 poco_check_ptr (pConnection. get (); 115 beginConnection (); 116 pConnection-> start (); 117 endConnection (); 118} 119} 120121 FastMutex: ScopedLock lock (_ mutex ); (gdb) n121 FastMutex: ScopedLock lock (_ mutex); (gdb) n122 if (_ stopped | (_ currentThreads> 1 & _ queue. empty () (gdb) l117 endConnection (); 118} 119} 120121 FastMutex: ScopedLock (_ mutex ); 122 if (_ stopped | (_ currentThreads> 1 & _ queue. empty () 123 {124 -- _ currentThreads; 125 break; 126} (gdb) cContinuing. breakpoint 1, 0x0804be43 in TimeServerConnection: run () (gdb)

This allows debugging.

 

If any error occurs in this article, please kindly advise. Thank you.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.