简体   繁体   中英

fix Mangled Export names in C++

I am new to C++ and wanted to write a DLL with some exports, but I'm getting mangled names when compiled. I know by now that in order to fix this I should add extern "C" in front of the declaration, but this still doesn't work.

My Code

#pragma once
#include <iostream>
#include <windows.h>

using namespace std;

#ifdef FXSST_EXPORTS
#define FXSST_API __declspec(dllexport)
#else
#define FXSST_API __declspec(dllimport)
#endif

extern "C" FXSST_API void Hello(void);
FXSST_API void Hello(void)
{
    cout << "Hello World" << endl;
}

For personal reasons (and making it easier for myself), I'd like to keep everything in one .cpp file if possible.

Thanks ;)

The easiest thing would be to setup your DLL project to create an import library (.lib) with a header (.h) file that declares your class. Then you add the .lib to your link libraries in the project that uses the DLL, and #include your header where you need to use the class.

MSDN on building dlls

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM