Ubuntu下生成bin文件和.so文件


Ubuntu下生成bin文件和.so文件(ubuntu下.so文件对应是windows下.dll文件,都为动态链接库)## 标题


编译链接生成.so文件或者可执行文件时候,需要注意如下几点:
每一个工程里面必须包含这三个文件,并且里面有严格的书写规范。
naoqi-sdk-xxx.xx.xx/doc/examples/vision/motionexample 为例子进行讲解
1、文件如下:

cmake_minimum_required(VERSION 2.6.4 FATAL_ERROR)
project(motionexample[工程名])
find_package(qibuild[固定格式,qibuild])

option(MOTIONEXAMPLE[大写工程名]_IS_REMOTE
  "module is compiled as a remote module (ON or OFF)"
  ON[此处是OFF还是ON,就看你是准备生成sdk/bin文件下的可执行文件还是生成naiqi/sdk目录下的.so文件。如果你选择ON,接下来你将生成的是dk/bin文件下的可执行文件,如果你选择的是OFF,接下来你将身上是.so文件])

set(_srcs
  main.cpp
  almotionexample.h
  almotionexample.cpp[这里包含着你工程cpp文件]
)

if(MOTIONEXAMPLE[工程名大学]_IS_REMOTE)
  add_definitions(" -D[-D你不用管,固定格式]MOTIONEXAMPLE[工程名大学]_IS_REMOTE ")
  qi_create_bin(motionexample[工程名小写] ${_srcs})
else()
  qi_create_lib(motionexample[工程名大学] SHARED ${_srcs} SUBFOLDER naoqi)
endif()

qi_use_lib(motionexample[工程名小写] ALCOMMON ALMATH)

2、接下来是对qiproject.xml文件进行说明:

<project name="motionexample[此处是你的工程名]"/>

3、接下来是对mian.cpp文件进行说明:

/**
* @author Chris Kilner
* Copyright (c) Aldebaran Robotics 2007 All Rights Reserved
*/

#include <signal.h>
#include <boost/shared_ptr.hpp>
#include <alcommon/albroker.h>
#include <alcommon/almodule.h>
#include <alcommon/albrokermanager.h>
#include <alcommon/altoolsmain.h>
#include "almotionexample.h"

#ifdef MOTIONEXAMPLE_IS_REMOTE
# define ALCALL
#else
# ifdef _WIN32
#  define ALCALL __declspec(dllexport)
# else
#  define ALCALL
# endif
#endif

extern "C"[外部接口函数,为python程序调用C程序提供了方便]
{

ALCALL int _createModule(boost::shared_ptr<AL::ALBroker> pBroker)
{
  // init broker with the main broker instance
  // from the parent executable
  AL::ALBrokerManager::setInstance(pBroker->fBrokerManager.lock());
  AL::ALBrokerManager::getInstance()->addBroker(pBroker);
  AL::ALModule::createModule<ALMotionExample>( pBroker, "ALMotionExample[此处是你提供给外部接口的名称,通过这个接口,python程序可以调用里面函数]");
  return 0;
}

ALCALL int _closeModule()
{
  return 0;
}[外部接口书写格式]

} // extern "C"


#ifdef MOTIONEXAMPLE_IS_REMOTE

int main(int argc, char *argv[])
{
  // pointer to createModule
  TMainType sig;
  sig = &_createModule;

  // call main
  ALTools::mainFunction("motionexample",argc, argv,sig);
}
#endif

接下来是如何编译.so文件
打开cmake界面,where is the source code上导入你的工程路径,where to build the binaries写入你需要生成makefile文件路径。(建议你就在where is the source code你的工程路径上后加/build即可)
以我的工程路径为例:
where is the source code 上写入”home/zou/Desktop/motionexample”
where to build the binaries 上写入”home/zou/Desktop/motionexample/build”

如果你想生成可执行文件:
点解configure,选中MOTIONEXAMPLE_IS_REMOTE,再Generate。
进入终端,进入工程文件下build下目录,输入make命令,系统自动生成可执行文件。
可执行文件所在位置在build/sdk/bin的目录下。

如果你想生成.so文件:
点解configure,不选中MOTIONEXAMPLE_IS_REMOTE,再Generate。
进入终端,进入工程文件下build下目录,输入make命令,系统自动生成.so文件。
.so文件所在位置在naoqi-sdk/lib/naoqi的目录下。
这里写图片描述

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值