Zthread library configuration, Windows & Linux

Source: Internet
Author: User

The zthread library is an open-source cross-platform advanced object-oriented linear and sycnchronization library that runs C ++ programs in POSIX and Win32 systems.

Zthread Library Home Page: http://zthread.sourceforge.net

The latest version of zthread far it: http://go.rritw.com/prdownloads.sourceforge.net/zthread/ZThread-2.3.2.tar.gz

Zthread document: http://go.rritw.com/zthread.sourceforge.net/documentation.html

1. Use zthread in Windows

First, download zthread, decompress to a directory, I decompress to D: \ libs \ ZThread-2.3.2.

Method 1: include source files for direct compilation (not recommended)

1. In vs2010, create a new Win32 console project and select an empty project.

2. Create a new main. cpp file in the source directory and copy a sample code in the http://go.rritw.com/zthread.sourceforge.net/html/classZThread_1_1Thread.html to main. cpp.

3. In the configuration properties of the project, add the zthread header file directory to the Directory included in the VC ++ directory. Here I am: D: \ libs \ ZThread-2.3.2 \ include. The Configuration Attribute is divided into debug and release. The default configuration is debug, but it is best to configure both. Otherwise, an error will be reported when the release version is generated.

4. create a new folder in the project with a random name. My name is zthread. Then, right-click the folder and choose add> existing items, add all cxx files in the src directory in the zthread decompress directory to this directory.

Now you can compile the program. Normally, the program should be compiled and started successfully.

However, some errors may also occur:

Error 1: Error c2664: "getmodulehandlew": parameter 1 cannot be converted from "const char [13]" to "lpcwstr"

This is because the Unicode character set is used by default in vs2010 Project Settings. You can change the character set to multi-byte in the project properties, or add _ T () to the string parameter of the getmodulehandle function () include, change to getmodulehandle (_ T ("kernel32.dll "));

 

 

Method 2: Compile to a static library

1. In vs2010, create a new Win32 console project named zthread. and select static library as the project type.

2. In the configuration properties of the project, add the zthread header file directory to the Directory included in the VC ++ directory. Here I am: D: \ libs \ ZThread-2.3.2 \ include. The Configuration Attribute is divided into debug and release. The default configuration is debug, but it is best to configure both. Otherwise, an error will be reported when the release version is generated.

3. In the project source directory, right-click and choose add> existing items to add all the cxx files in the src directory in the zthread decompress directory to this directory.

Now we can compile it. Normally, we should compile it and generate the zthread. Lib static library.

However, some errors may also occur:

Error 1: Error c2664: "getmodulehandlew": parameter 1 cannot be converted from "const char [13]" to "lpcwstr"

This is because the Unicode character set is used by default in vs2010 Project Settings. You can change the character set to multi-byte in the project properties, or add _ T () to the string parameter of the getmodulehandle function () include, change to getmodulehandle (_ T ("kernel32.dll "));

The static library is used as follows:

Add the zthread header file directory to the include directory of the VC ++ directory of the Project attribute of our program.

In the program code, add the # pragma comment (Lib, "zthread. lib") Declaration. At the same time, you need to put the zthread. Lib file in our source directory and put it together with the code.

 

Method 3: compile it into a dynamic library DLL

(Note: VS may only generate DLL without corresponding Lib. The solution is to create any def file in the project and compile it)

Similar to method 2, except that the project type is dynamic library. Similar to other steps, zthread. lib and zthread. dll are generated after compilation.

The method for using a dynamic library is the same as that for a static library. The difference is that a program using a dynamic library requires the zthread. dll file during runtime.

So far, we have finished talking about static and dynamic link libraries. Let's make a comparison and supplement:

Differences between the two lib files

We found that both static and dynamic libraries have lib files. What is the difference between the two? Actually, two are completely different. The two zthread. Lib files have different sizes. The LIB files corresponding to the static library are called static libraries, and the Lib files corresponding to the dynamic library are called imported to the database. In fact, the static library itself contains the actual execution code, symbol table, and so on. For the import and export operations, the actual execution code is located in the dynamic library, the imported database only contains the address symbol table. Make sure that the program finds some basic address information of the corresponding function.

For static link libraries, all the code has been imported during compilation and linking. Therefore, after an executable file is generated, the executable file contains all the code. Therefore, the static library is no longer needed when the executable file is run, which is why we delete zthread. the Lib program is still executed. For dynamic link libraries, the executable file does not contain the content in the DLL, but is imported to the database through the import (. lib) knows the corresponding address information, so the executable file needs to dynamically load the DLL at runtime, which is why we delete zthread. after the DLL, the program cannot be executed.

For DLL, we can avoid lib files. If the Lib file is not required, we can use the function pointer to achieve our goal.

 

Ii. Use zthread in Linux

In Linux, the trilogy can be used directly, which is very simple.

./Configure

./Make

./Make install

If an error occurs during make:

../Include/zthread/guard. H: In destructor 'zthread: Guard <locktype, lockingpolicy> ::~ Guard ()':

../Include/zthread/guard. h: 494: Error: there are no arguments to 'isdisabled 'that depend on a template parameter, so a declaration of 'isdisabled' must be available

You only need to export cxxflags =-fpermissive and then execute

./Configure

./Make

./Make install

You can.

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.