English 中文(简体)
C++:有线性功能的进出口
原标题:C++ : inline functions with dllimport/dllexport?

我设立了一个DL(say CORE.DLL),我有以下班级/职务:

#ifdef RINZOCORE_SHARED
#define RINZO_LIB __declspec(dllexport)
#else
#define RINZO_LIB __declspec(dllimport)
#endif

我将许多在线职能定义为“出口”宏观,

class RINZO_LIB CVector
{

public:
    CVector();//!< default constructor
    ..
    real& x();//!< accessor for the x component (can be used as l-value too)
    real& y();//!< accessor for the y component (can be used as l-value too)
    real& z();//!< accessor for the z component (can be used as l-value too)
    CVector& operator=(const CVector& other);//!< the assignment
    CVector& operator+=(const CVector& other);//!< the sum & assign
    CVector& operator-=(const CVector& other);//!< the subtract & assign
    CVector& operator*=(const real& fact);//!< the short multiply by a scalar factor & assign
    CVector& operator/=(const real& fact);//!< the short divide by a scalar factor & assign
..
}

RINZO_LIB inline CVector& CVector::operator=(const CVector& other)
{
    //check for  a=a  case
    if (this==&other) return *this;
    vec[0]=other.vec[0];
    vec[1]=other.vec[1];
    vec[2]=other.vec[2];
    return *this;
}

RINZO_LIB inline CVector& CVector::operator+=(const CVector& other)
{
    vec[0]+=other.vec[0];
    vec[1]+=other.vec[1];
    vec[2]+=other.vec[2];
    return *this;
}

RINZO_LIB inline CVector& CVector::operator-=(const CVector& other)
{
    vec[0]-=other.vec[0];
    vec[1]-=other.vec[1];
    vec[2]-=other.vec[2];
    return *this;
}

RINZO_LIB inline CVector& CVector::operator*=(const real& fact)
{
    vec[0]*=fact;
    vec[1]*=fact;
    vec[2]*=fact;
    return *this;
}

RINZO_LIB inline CVector& CVector::operator/=(const real& fact)
{
    assert(fabs(fact) >= epsilon);
    vec[0]/=fact;
    vec[1]/=fact;
    vec[2]/=fact;
    return *this;
}

但是,当我使用DL(进口)汇编另一个DLL(say PluginA.DLL)时,它汇编了以下错误:

Info: resolving std::cout  by linking to __imp___ZSt4cout (auto-import)
CMakeFilesContourViewer.dir/objects.a(RzStateDoAnimation.cpp.obj):C:/svn/osaka3d/trunk/osaka3d/rinzo-platform/src/dlplugins/contourviewer/statemachine/RzStateDoAnimation.cpp:79: undefined reference to `operator!=(quaternion const&, quaternion const&) 
Info: resolving vtable for __cxxabiv1::__vmi_class_type_info by linking to __imp___ZTVN10__cxxabiv121__vmi_class_type_infoE (auto-import)
CMakeFilesContourViewer.dir/objects.a(RzStateDoAnimation.cpp.obj):C:/svn/osaka3d/trunk/osaka3d/rinzo-platform/src/dlplugins/contourviewer/statemachine/RzStateDoAnimation.cpp:146: undefined reference to `operator==(quaternion const&, quaternion const&) 
CMakeFilesContourViewer.dir/objects.a(BallController.cpp.obj):C:/svn/osaka3d/trunk/osaka3d/rinzo-platform/src/dlplugins/contourviewer/trackball/BallController.cpp:159: undefined reference to `operator*(CVector const&, CVector const&) 
CMakeFilesContourViewer.dir/objects.a(BallController.cpp.obj):C:/svn/osaka3d/trunk/osaka3d/rinzo-platform/src/dlplugins/contourviewer/trackball/BallController.cpp:165: undefined reference to `operator^(CVector const&, CVector const&) 
CMakeFilesContourViewer.dir/objects.a(BallController.cpp.obj):C:/svn/osaka3d/trunk/osaka3d/rinzo-platform/src/dlplugins/contourviewer/trackball/BallController.cpp:168: undefined reference to `operator-(CVector const&, CVector const&) 
CMakeFilesContourViewer.dir/objects.a(BallController.cpp.obj):C:/svn/osaka3d/trunk/osaka3d/rinzo-platform/src/dlplugins/contourviewer/trackball/BallController.cpp:292: undefined reference to `operator*(CVector const&, CVector const&) 
CMakeFilesContourViewer.dir/objects.a(BallController.cpp.obj):C:/svn/osaka3d/trunk/osaka3d/rinzo-platform/src/dlplugins/contourviewer/trackball/BallController.cpp:292: undefined reference to `operator*(CVector const&, float const&) 
CMakeFilesContourViewer.dir/objects.a(BallController.cpp.obj):C:/svn/osaka3d/trunk/osaka3d/rinzo-platform/src/dlplugins/contourviewer/trackball/BallController.cpp:292: undefined reference to `operator-(CVector const&, CVector const&) 

任何关于如何使用拖拉出口/进口的线性功能的问题?

最佳回答

<说明>:由于这是公认的答案,因此不能删除。 删除。 各位欢迎你取消否决权。

原始内容保存在下文,供历史参考。


Inline and dllexport/dllimport dos.

页: 1

  1. inline your functions, and have them compiled separately for each source file that uses them; or
  2. store them in a library, that is, have them compiled just once (export them), and link the rest of the program against that single compiled version (import them).

试图同时这样做没有什么意义。

删除每个功能定义中既有的<代码>inline, 或RINZO_LIB, 并且应当予以罚款。

<><>Edit>/strong> 消除任何误解:它可以出口和进口在线职能,事实上只是将出口/进口的批量放在申报上。

问题回答

我愿提供一些额外信息,因为这是一个非常棘手的问题,在出口/进口的线索上,出现了不正确的信息。

首先,在线功能可在无问题的情况下用于进出口。 意思是完全明智的:你提供了一条在线定义,可在你的当地或外部使用客户代码(可以上网查阅),但还是可以查阅标准出口功能。 换言之,如果你需要的话,你仍然可以找到执行<中居住的职能的联络点。 举例来说,使用的案例包括:通过FFI获得这一功能,能够获得记忆分配/免费例行公事,这些传闻应在单元内标明,但需要将DL的斜体用于跨越DL边界的记忆。

请见https://devblogs.microsoft.com/oldnewth/20140109-00/?p=2123 要求彻底处理和澄清它意味着同时出口/进口。

Next, in your specific case, I see nothing immediately wrong with what you re trying to do. You want to provide fast, inlined vector math for yourself and clients, while still being able to access that function as though it were a standard export. If that last bit isn t true (i.e., you don t ever explicitly need a pointer to the DLL s implementation of the function), then the comments/answer are correct: remove the export/import and make it part of the .hpp. Use import/export + inline only when you know that you will still require access to the DLL s exported version of the function. Again, this is a perfectly-reasonable thing, however, it s not usually what s required -- so make sure you do indeed require it.

尽管如此,它还是看着你们的利比里亚民族解放组织没有出口这些标志。

Double-check to make sure that you re defining RINZOCORE_SHARED when you build the library. Check the DLL s symbols and see if those functions have been exported (if not, and you re positive that you ve defined RINZOCORE_SHARED, then I m really quite stumped).

检查,确保你从你再次要求的地方,包括具有职能定义的负责人。 检查,以确保<代码>RINZOCORE_SHARED是贵方建筑界定的NOT。 这似乎意味着它没有这些在线职能中的定义>。

I usually use this only with C-linkage functions, so I m honestly not quite sure what all could be going wrong in terms of the C++ ABI.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?