How to Use the FFMPEG static library in a project

Source: Internet
Author: User

Recently, I was working on a project. At first, this project was composed of an EXE and several dynamic libraries. Now I want to convert some dynamic libraries into static libraries, in vs2010, right-click the project name and choose "properties"> "configuration properties"> "general"> "project default"> "configuration type (. DLL) to the static library (. lib), re-compile the project, compile successfully, but there are many Link errors when re-generate the EXE; after modification, the problem cannot be solved; so I calmed down and wrote a test project;

There are two projects A and B in the project. A is the console application, B is the Win32 dynamic library, and B writes a simple function _ declspec (dllexport)
Int myadd (int A, intb)

{

Return A + B;

}

It is okay to call and output the result in,

Then, change the project type of B to the static library, and regenerate a. A connection error occurs. Check carefully and find that there is a _ declspec (dllexport) in front of the myadd statement) this is used by the dynamic library export function. If _ declspec (dllexport) is removed to regenerate B, A is successful and the operation is okay. I'm so excited.

Then, delete all _ declspec (dllexport) in the original project and generate a new one. The connection error still persists. Baidu and Google did not find the answer, as a result, I was quietly observing the output error information, and found that all these connection errors were caused by the failure to find the function of the static library call system or d3d. I didn't say that the export function of the static library could not be found, so I suddenly realized that, when other dynamic libraries are called in the static library, they are called according to the rules of the dynamic library, place the library files referenced by the static library on the link in the DLL or EXE that needs to call these static libraries-> re-generate the files in the input file. If the file is successful, you will be excited. If the file runs properly, you will be excited;

Here, we will use a fuzzy summary to convert the existing DLL into a static library. Pay attention to the following two points:

1: remove the _ declspec (dllexport) before the declaration of the function to be exported from the dynamic library, so that the export function of the static library will not be found during the link;

2: reference the library files referenced by the dynamic library in the EXE or DLL that calls the Library (although these projects do not directly reference these library files) in this way, the function in the dynamic library cannot be referenced by the static library during the connection.

Use of FFMPEG static library in vs2010

First, compile the FFMPEG static library in the mingw environment. Note that the generated static library name is in the form of LIB ***. A, rather than the. Lib file.

In the project connection-> enter the following Library

Libgcc.

Libmingwex. Lib

Libavcodec.

Libavformat.

Libavutil.

Libswscale.

Libz.

Libbz2.a

Libpthreadgc2.a

Libmingwex. Lib

Use the following method;

1. First Run CMD and run vcvars32.bat in the VC/bin directory under the vs installation directory in cmd (my computer path is c: \ ProgramFiles (x86) \ Microsoft Visual Studio 10.0 \ Vc \ bin), configure the vs environment, note that the configuration environment is only valid in the current cmd window.

2. Run

Cd c: \ msys \ 1.0 \ mingw \ Lib

Enter the mingw directory. The specific path depends on the environment you have installed, as long as you enter libmingwex. Lib

Directory.

3. Run

Lib-Remove: mbrtowc. O libmingwex.

Lib-Remove: mcrtomb. O libmingwex. Lib

The generated libmingwex. lib can be used.

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.