DLL 导出:并非所有函数都导出

DLL Exports: not all my functions are exported

本文关键字:函数 导出 DLL      更新时间:2023-10-16

我正在尝试创建一个导出许多函数的 Windows DLL,但我的所有函数都导出了一个!!

我想不通。

我使用的宏是这个简单的:

__declspec(dllexport) void myfunction();

它适用于我的所有功能,除了一个。我看过Dependency Walker的内部,他们都在这里,除了一个。

这怎么可能?这是什么原因呢?我被卡住了。

编辑:更准确地说,这是 .h 中的函数:

namespace my {
namespace great {
namespace namespaaace {
__declspec(dllexport) void prob_dump(const char *filename,
        const double    p[],  int  nx,       const double Q[],
        const double xlow[],  const char ixlow[], 
        const double xupp[],  const char ixupp[],
        const double    A[],  int  my,       const double   bA[],
        const double    C[],  int  mz,
        const double clow[],  const char iclow[],
        const double cupp[],  const char icupp[]
        );
}}}

在.cpp文件中,它是这样的:

namespace my {
namespace great {
namespace namespaaace {

 namespace {
void dump_mtx(std::ostream& ostr, const double *mtx, int rows, int cols, const char *ind = 0)
  {
       /* some random code there, nothing special, no statics whatsoever */
  }
    } // end anonymous namespace here
  // dump the problem specification into a file
  void prob_dump(
    const char *filename,
    const double    p[],  int  nx,       const double Q[],
    const double xlow[],  const char ixlow[], 
    const double xupp[],  const char ixupp[],
    const double    A[],  int  my,       const double   bA[],
    const double    C[],  int  mz,
    const double clow[],  const char iclow[],
    const double cupp[],  const char icupp[]
    )
   {
    std::ofstream fout;
    fout.open(filename, std::ios::trunc);
    /* implementation there */
    dump_mtx(fout, Q, nx, nx);
   }
}}}

谢谢

我找到了一个解决方法:

当我将__declspec(dllexport)添加到函数定义时,在 cpp 文件中,它将被导出。

我绝对不知道为什么这会起作用,因为 MSDN 似乎没有提到这样做。

你不在乎说得足够多,无法真正帮助你,但这里有一些你可以检查的事情。

确保通过手动删除文件并重新生成项目来生成.dll文件。

您是否也在使用 .def 文件?

只能导出类中的公共成员函数。