使用Clang ++编译OmniORB4

时间:2018-02-27 09:51:39

标签: c++ c++17 clang++ omniorb

我正在使用OmniORB学习Corba并尝试编译简单的示例程序,但它不起作用。不幸的是,很难找到一些如何做到这一点的信息。

我的表现如下:

  1. 我在idl目录

    中制作了简单的界面文件
    interface IssueAlert {
      string sendAlert(in string alert);
    };
    
  2. 使用omniidl -bcxx -Wbexamples echo.idl

  3. 进行编译
  4. 我获取结果文件并使用示例将该代码作为服务器应用程序。

    #include "idl/echo.hh"
    #include <iostream>
    using namespace std;
    
    
    class IssueAlert_i : public POA_IssueAlert {
      public:
        IssueAlert_i();
        virtual ~IssueAlert_i();
        char* sendAlert(const char* alert);
    };
    
    IssueAlert_i::IssueAlert_i(){}
    IssueAlert_i::~IssueAlert_i(){}
    
    char* IssueAlert_i::sendAlert(const char* alert){
      cout << "Upcall: " << alert << endl;
      return CORBA::string_dup(alert);
    }
    
    //////////////////////////////////////////////////////////////////////
    
    int main(int argc, char** argv){
       try {
         CORBA::ORB_var          orb = CORBA::ORB_init(argc, argv);
         CORBA::Object_var       obj = orb->resolve_initial_references("RootPOA");
         PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
    
         PortableServer::Servant_var<IssueAlert_i> issue = new 
         IssueAlert_i();
    
         PortableServer::ObjectId_var issue_id = poa->activate_object(issue);
    
          // Obtain a reference to the object, and print it out as a
          // stringified IOR.
          obj = issue->_this();
          CORBA::String_var sior(orb->object_to_string(obj));
          cout << sior << endl;
    
          PortableServer::POAManager_var pman = poa->the_POAManager();
          pman->activate();
    
          // Block until the ORB is shut down.
          orb->run();
       }catch (CORBA::SystemException& ex) {
         cerr << "Caught CORBA::" << ex._name() << endl;
       }catch (CORBA::Exception& ex) {
         cerr << "Caught CORBA::Exception: " << ex._name() << endl;
       }
       return 0;
    }
    
  5. 使用命令编译它:

    clang++ -std=c++17 -Wall -Wextra -Wnarrowing -Wsign-conversion -lomniORB4 -lomnithread -lomniDynamic4 servant.cpp -I/usr/include -L/usr/lib64/ -o server
    
  6. yum安装的所有OmniORB内容都在/usr/include/usr/lib64中。 我收到了这个错误:

        /tmp/servant-e9e6b6.o: In function `IssueAlert_i::IssueAlert_i()':
        servant.cpp:(.text+0x148): undefined reference to `_impl_IssueAlert::~_impl_IssueAlert()'
        /tmp/servant-e9e6b6.o: In function `IssueAlert_i::~IssueAlert_i()':
        servant.cpp:(.text+0x198): undefined reference to                 `POA_IssueAlert::~POA_IssueAlert()'
        /tmp/servant-e9e6b6.o: In function `IssueAlert_i::~IssueAlert_i()':
        servant.cpp:(.text+0x201): undefined reference to `_impl_IssueAlert::~_impl_IssueAlert()'
        /tmp/servant-e9e6b6.o: In function `POA_IssueAlert::_this()':
        servant.cpp:
        (.text._ZN14POA_IssueAlert5_thisEv[_ZN14POA_IssueAlert5_thisEv]+0x1e): undefined reference to `IssueAlert::_PD_repoId'
        /tmp/servant-e9e6b6.o:(.rodata+0x68): undefined reference to `_impl_IssueAlert::_dispatch(omniCallHandle&)'
        /tmp/servant-e9e6b6.o:(.rodata+0x70): undefined reference to `_impl_IssueAlert::_ptrToInterface(char const*)'
        /tmp/servant-e9e6b6.o:(.rodata+0x78): undefined reference to `_impl_IssueAlert::_mostDerivedRepoId()'
        /tmp/servant-e9e6b6.o:(.rodata+0xf0): undefined reference to `virtual thunk to _impl_IssueAlert::_ptrToInterface(char const*)'
        /tmp/servant-e9e6b6.o:(.rodata+0x100): undefined reference to `virtual thunk to _impl_IssueAlert::_mostDerivedRepoId()'
        /tmp/servant-e9e6b6.o:(.rodata+0x120): undefined reference to `virtual thunk to _impl_IssueAlert::_dispatch(omniCallHandle&)'
        /tmp/servant-e9e6b6.o:(.rodata+0x288): undefined reference to `typeinfo for POA_IssueAlert'
        /tmp/servant-e9e6b6.o:(.rodata+0x290): undefined reference to `POA_IssueAlert::~POA_IssueAlert()'
        /tmp/servant-e9e6b6.o:(.rodata+0x298): undefined reference to `POA_IssueAlert::~POA_IssueAlert()'
        /tmp/servant-e9e6b6.o:(.rodata+0x2a8): undefined reference to `_impl_IssueAlert::_dispatch(omniCallHandle&)'
        /tmp/servant-e9e6b6.o:(.rodata+0x2b0): undefined reference to `_impl_IssueAlert::_ptrToInterface(char const*)'
        /tmp/servant-e9e6b6.o:(.rodata+0x2b8): undefined reference to `_impl_IssueAlert::_mostDerivedRepoId()'
        /tmp/servant-e9e6b6.o:(.rodata+0x318): undefined reference to `typeinfo for POA_IssueAlert'
        /tmp/servant-e9e6b6.o:(.rodata+0x320): undefined reference to `virtual thunk to POA_IssueAlert::~POA_IssueAlert()'
        /tmp/servant-e9e6b6.o:(.rodata+0x328): undefined reference to `virtual thunk to POA_IssueAlert::~POA_IssueAlert()'
        /tmp/servant-e9e6b6.o:(.rodata+0x330): undefined reference to `virtual thunk to _impl_IssueAlert::_ptrToInterface(char const*)'
        /tmp/servant-e9e6b6.o:(.rodata+0x340): undefined reference to `virtual thunk to _impl_IssueAlert::_mostDerivedRepoId()'
        /tmp/servant-e9e6b6.o:(.rodata+0x360): undefined reference to `virtual thunk to _impl_IssueAlert::_dispatch(omniCallHandle&)'
        /tmp/servant-e9e6b6.o:(.rodata+0x3c8): undefined reference to `typeinfo for POA_IssueAlert'
        /tmp/servant-e9e6b6.o:(.rodata+0x3d0): undefined reference to `virtual thunk to POA_IssueAlert::~POA_IssueAlert()'
        /tmp/servant-e9e6b6.o:(.rodata+0x3d8): undefined reference to `virtual thunk to POA_IssueAlert::~POA_IssueAlert()'
        /tmp/servant-e9e6b6.o:(.rodata+0x458): undefined reference to `typeinfo for _impl_IssueAlert'
        /tmp/servant-e9e6b6.o:(.rodata+0x460): undefined reference to `_impl_IssueAlert::~_impl_IssueAlert()'
        /tmp/servant-e9e6b6.o:(.rodata+0x468): undefined reference to `_impl_IssueAlert::~_impl_IssueAlert()'
        /tmp/servant-e9e6b6.o:(.rodata+0x478): undefined reference to `_impl_IssueAlert::_dispatch(omniCallHandle&)'
        /tmp/servant-e9e6b6.o:(.rodata+0x480): undefined reference to `_impl_IssueAlert::_ptrToInterface(char const*)'
        /tmp/servant-e9e6b6.o:(.rodata+0x488): undefined reference to `_impl_IssueAlert::_mostDerivedRepoId()'
        /tmp/servant-e9e6b6.o:(.rodata+0x4e8): undefined reference to `typeinfo for _impl_IssueAlert'
        /tmp/servant-e9e6b6.o:(.rodata+0x4f0): undefined reference to `virtual thunk to _impl_IssueAlert::~_impl_IssueAlert()'
        /tmp/servant-e9e6b6.o:(.rodata+0x4f8): undefined reference to `virtual thunk to _impl_IssueAlert::~_impl_IssueAlert()'
        /tmp/servant-e9e6b6.o:(.rodata+0x500): undefined reference to `virtual thunk to _impl_IssueAlert::_ptrToInterface(char const*)'
        /tmp/servant-e9e6b6.o:(.rodata+0x510): undefined reference to `virtual thunk to _impl_IssueAlert::_mostDerivedRepoId()'
        /tmp/servant-e9e6b6.o:(.rodata+0x530): undefined reference to `virtual thunk to _impl_IssueAlert::_dispatch(omniCallHandle&)'
        /tmp/servant-e9e6b6.o:(.rodata+0x6d0): undefined reference to `typeinfo for POA_IssueAlert'
        clang-5.0: error: linker command failed with exit code 1 (use -v to see invocation)
    

    有人可以帮助我完成这个编译 - 我想要做的最后一个项目必须使用C ++ 17然后最好将继续使用这个编译器。

1 个答案:

答案 0 :(得分:0)

找到解决方案:

clang++ -std=c++17 -Wall -Wextra -Wnarrowing -Wsign-conversion -lomniORB4 -lomnithread -lomniDynamic4 servant.cpp idl/echoSK.cc -o server

只需要将echoSK.cc添加到命令中。