Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am new to Linux, but I have tried Ubuntu for basic stuff and I really like it. I want to explore the possibility to switch from Windows. However, at the moment I am working with Microsoft Visual Studio to develop a DLL written in C++. The DLL is to be used together with a software in Windows (there is no Linux counterpart).

Is there an easy way to do this from Ubuntu? if so, how? Some people have mentioned Mingw cross-compiler, but I want to know if this is the best option or if there are more options out there.


share|improve this question

Here is the Mingw solution:
Source file:

#include <stdio.h>
#include "example_dll.h"

__stdcall void hello(const char *s)
        printf("Hello %s\n", s);
int Double(int x)
        return 2 * x;
void CppFunc(void)
void MyClass::func(void)

Header file:


#ifdef __cplusplus
extern "C" {

#define EXAMPLE_DLL __declspec(dllexport)
#define EXAMPLE_DLL __declspec(dllimport)

void __stdcall EXAMPLE_DLL hello(const char *s);

int EXAMPLE_DLL Double(int x);

#ifdef __cplusplus

// NOTE: this function is not declared extern "C"
void EXAMPLE_DLL CppFunc(void);

// NOTE: this class must not be declared extern "C"
class EXAMPLE_DLL MyClass
        MyClass() {};
        virtual ~MyClass() {};
        void func(void);

#endif  // EXAMPLE_DLL_H


g++ -c -DBUILDING_EXAMPLE_DLL example_dll.cpp
g++ -shared -o example_dll.dll example_dll.o -Wl,--out-implib,libexample_dll.a
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.