Iconv static library Compilation

Source: Internet
Author: User

Keywords: vs2008 compiling iconv windows

Small open-source code conversion library. You don't need to talk about it ~ :)

I. First prepare the file:

1. Download The iconv library. The latest version is 1.31.
Http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
2. Go to www.d2school.com to download iconvpp

(This is not necessary, but it provides C ++ encapsulation, which is very convenient to use. Thank you, teacher Nanyu ).

 

Unzip the libiconv-1.13.1.tar.gzZipdir
Create solution directoryProjectdir

 

Zipdir: Decompress the iconv package file directory
Procjectdir: main directory for project Compilation

Ii. Merge files
1. Copy iconvpp. cpp to projectdir
2. Copy all files under zipdir/lib/to projectdir/_ iconv/(including subfolders)
3. Copy zipdir/include/iconv. H. In to projectdir/_ iconv/iconv. h.
4. Copy zipdir/scrlib/localcharset. h to projectdir/_ iconv/
5. Copy zipdir/libcharset/lib/localcharset. C to projectdir/_ iconv
6. Rename projectdir/_ iconv/config. H. In-> config. h

Batch Processing

@ ECHO: Copy all files to this directory: _ iconv
Pause
MD _ iconv

Copy lib/* _ iconv/
Copy include/iconv. H. In _ iconv/iconv. h
Copy srclib/localcharset. H _ iconv/
Copy libcharset/lib/localcharset. C _ iconv/
Ren _ iconv/config. H. In config. h

@ ECHO: the directory file is successfully generated.
Pause

OK. All files are prepared (under _ iconv ).

 

3., The following uses vs2008 to build a project ~ :
1. Create a Win32 project named iconvlib. Select "create solution directory" and select "static Link Library" without selecting "pre-compiled Header.

2. Copy the _ iconv directory.

3. Copy include and SRC in iconvpp.

The directory structure is as follows:

-Projectdir
├ ── Iconvlib
├ ── Iconvpp
│ Define-include
│ ─ ── Iconvpp
│ ─ ── SRC
─ ── _ Iconv

4. Add existing items and add iconvpp. cpp, iconv. C, and localcharset. C to the project.

5. Project properties-> C/C ++-> additional include directory: ../_ iconv; ../iconvpp/include;
6. Project properties-> C/C ++-> code generation-> Runtime Library-> multi-thread debugging (/MTD)

At this time, if there will be a bunch of errors during compilation, let's modify some locations.

 

4. Modify the file content:
1. iconv. h:

1). Delete All @ symbols (14 points)
2). Modify 25 rows: extern dll_variable int _ libiconv_version;

It is extern/* dll_variable */INT _ libiconv_version;
3). Modify 83 rows: extern size_t iconv (iconv_t CD, iconv_const char ** inbuf, size_t * inbytesleft, char ** outbuf, size_t * outbytesleft );

It is extern size_t iconv (iconv_t CD, const char ** inbuf, size_t * inbytesleft, char ** outbuf, size_t * outbytesleft );

2. localcharset. C:

Comment out 76 rows: # include "configmake. H"

The OK file is modified. At this time, the compilation will pass ~.

 

V. Test

Create a console project.

Set the project property header file to the following directories: _ iconv and iconvpp/include.

Link to debug/iconvlib. Lib

Runtime Library-> multi-thread debugging (/MTD)

# Include "iconvpp/iconvpp. H"

Using namespace iconvpp;
Using namespace STD;

Int _ tmain (INT argc, _ tchar * argv [])
{
String STR;
STR = utf8convert: from_wstring (L "this is a test string ~ ");
Printf ("% s", str. c_str ());
Return 0;
}

The final directory structure is as follows:

-Projectdir

─ ── Debug
├ ── Exetest
│ Bai── debug
├ ── Iconvlib
│ Bai── debug
├ ── Iconvpp
│ Define-include
│ ─ ── Iconvpp
│ ─ ── SRC
─ ── _ Iconv

Vi. End

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.