Richard
Richard

Reputation: 27

How to link a C++ project_A which includes other third party C libraries to another project_B

I think this is a basic question, however I can not find any adequate posts about this topic or maybe I am just too stupid searching properly...

I have two projects in two different solutions. Project A is an application (.exe) using third party libs like ffmpeg (native C) and Project B is a DLL, which wants to use code of Project A (Purpose: A C# project is suppose to use funktionality of Project A via Project B). From my point of view I just have to add include path to Project A in order to include source files of it and set the linker input to the Project B .obj. However, when compiling Project B MSVS can not find the header file "libavutil/opt.h" of a ffmpeg Header:

#pragma once
extern "C"
{
#include <libavutil/opt.h>
#include <libavcodec/avcodec.h>
#include <libavutil/channel_layout.h>
#include <libavutil/common.h>
#include <libavutil/imgutils.h>
#include <libavutil/mathematics.h>
#include <libavutil/samplefmt.h>
}

fatal error C1083: Cannot open include file: 'libavutil/opt.h': No such file or directory.

Do I really have to set include paths to those ffmpeg libs? If doing so I get many LNK2001, 2005 and 2019 errors. Any Ideas?

Upvotes: 0

Views: 187

Answers (1)

Aconcagua
Aconcagua

Reputation: 25518

Sorry, there is no way around setting up the include paths for your project. Possibly, you might facilitate this task, however, have a look at here.

You might consider a complete redesign: If project B uses code from Project A, you might want to move all the code to project B and let project A use the DLL, too. If you find it easier making an EXE project a DLL than setting up the include path, you could switch the roles of A and B, renaming them and changing their types appropriately and moving the code not remaining in the DLL to Project B, using Project A as DLL.

Edit (in response to your comment):

  • Project DLL:
    Receives all the code that will be shared between the C++ exe and the C# exe, including linkage to ffmpeg, etc.
  • Project C++ EXE:
    Receives what yet remains of the former Project A. Will make use of Project DLL (more precisely: the DLL outputted from there) to get again whatever was previously incorporated directly.
  • Project C# EXE: As you intended before. Of course, all the marshalling between managed and unmanaged code remains (you would have had to do this before anyway).

Upvotes: 1

Related Questions