ubuntu 14.04安装出错加载动态库出错

int test1(){
return 1;}//test2.cint test2(){
return2;}//mytest.c#include &stdio.h&int test1();int test2();int main(){
printf("result of test1:= %d\n",test1());
printf("result of test2:= %d\n",test2());}打包成so文件在代码的目录下运行如下命令: (如果你不是Ubuntu系统,请将命令的sudo都去掉)gcc -Wall -fPIC -c *.cgcc -shared -Wl,-soname,libctest.so.1 -o libctest.so.1.0
*.osudo mv libctest.so.1.0 /usr/libsudo ln -sf /usr/lib/libctest.so.1.0 /usr/lib/libctest.sosudo ln -sf /usr/lib/libctest.so.1.0 /usr/lib/libctest.so.1参数详解:-Wall: 包含warning信息-fPIC: 编译动态库必须,输出不依赖位置的代码(原文 :Compiler directive to output position independent code)-shared: 编译动态库必需选项-W1: 向链接器(Linker)传递一些参数.在这里传递的参数有
"-soname libctest.so.1"-o: 动态库的名字. 在这个例子里最终生成动态库 libctest.so.1.0两个符号链接的含义:第一个:允许应用代码用 -lctest 的语法进行编译.第二个:允许应用程序在运行时调用动态库.<font color="# so路径设置为了使应用程序能够在运行时加载动态库,可以通过3种方式指定动态库的路径(以下例子均假定/opt/lib是动态库所在位置):用ldconfig指定路径运行 sudo ldconfig -n /opt/lib/opt/lib 是动态库所在路径.
这种方式简单快捷,便于程序员开发.缺点是重启后即失效.修改/etc/ld.so.conf文件打开/etc/ld.so.confg 文件,并将/opt/lib 添加进去. (注: 在Ubuntu系统中, 所有so.conf文件都在/etc/ld.so.conf.d目录. 你可以仿照该目录下的.conf文件写一个libctest.conf并将/opt/lib填入)用环境变量LD_LIBRARY_PATH指定路径环境变量的名字一般是LD_LIBRARY_PATH, 但是不同的系统可能有不同名字. 例如Linux/Solaris: LD_LIBRARY_PATH, SGI: LD_LIBRARYN32_PATH, AIX: LIBPATH, Mac OS X: DYLD_LIBRARY_PATH, HP-UX: SHLIB_PATH) (注: 此说法未经验证)
修改~/.bashrc , 增加以下脚本:if [ -d /opt/lib ];then
LD_LIBRARY_PATH=/opt/lib:$LD_LIBRARY_PATHfiexport LD_LIBRARY_PATH在第一章的简单例子中, /usr/lib 是Ubuntu默认的动态库目录,所以我们不须指定动态库目录也能运行应用程序.<font color="# 简单的动态调用so例子C调用例子保留第一章的test1.c和test2.c文件,并增加ctest.h头文件如下:#ifndef CTEST_H#define CTEST_H#ifdef __cplusplusextern "C" {#endifint test1();int test2();#ifdef __cplusplus}#endif#endif
我们继续使用第一章生成的libctest.so,仅需增加一个新的应用程序 prog.c://prog.c#include &stdio.h&#include &dlfcn.h&#include "ctest.h"int main(int argc, char **argv) {
void *lib_
int (*fn)();
lib_handle = dlopen("libctest.so", RTLD_LAZY);
if (!lib_handle)
fprintf(stderr, "%s\n", dlerror());
fn = dlsym(lib_handle, "test1");
if ((error = dlerror()) != NULL)
fprintf(stderr, "%s\n", error);
int y=fn();
printf("y=%d\n",y);
dlclose(lib_handle);
return 0;}
然后用如下命令运行(由于没有使用其他库,所以忽略-L等参数):gcc -Wall prog.c -lctest -o prog -ldl./progdl方法简介dlopen("libctest.so", RTLD_LAZY): 加载动态库,如果加载失败返回NULL. 第二个参数可以是:RTLD_LAZY: lazy模式. 直到源码运行到改行才尝试加载.RTLD_NOW: 马上加载.RTLD_GLOBAL: 不解(原文: Make symbol libraries visible.) dlsym(lib_handle, "test1"): 返回函数地址. 如果查找函数失败则返回NULL.和微软的动态加载dll技术对比如下:::LoadLibrary() - dlopen()
::GetProcAddress() - dlsym()
::FreeLibrary() - dlclose()
C++调用例子增加一个prog2.cpp#include &dlfcn.h&#include &iostream&#include "ctest.h"using namespaceint main(){
void *lib_
//MyClass* (*create)();
//ReturnType (* func_name)();
int (* func_handle)();
string nameOfLibToLoad("libctest.so");
lib_handle = dlopen(nameOfLibToLoad.c_str(), RTLD_LAZY);
if (!lib_handle) {
cerr && "Cannot load library: " && dlerror() &&
// reset errors
dlerror();
// load the symbols (handle to function "test")
//create = (MyClass* (*)())dlsym(handle, "create_object");
//destroy = (void (*)(MyClass*))dlsym(handle, "destroy_object");
func_handle =(int(*)())dlsym(lib_handle, "test1");
const char* dlsym_error = dlerror();
if (dlsym_error) {
cerr && "Cannot load symbol test1: " && dlsym_error &&
cout&&"result:= "&&func_handle()&&
dlclose(lib_handle);
return 0;}然后用如下命令运行:g++ -Wall prog2.cpp -lctest -o prog2 -ldl./prog2编译命令简介假设C文件是prog.c, C++调用文件是prog2.cpp,那么编译脚本分别是:C语言: gcc -Wall -I/path/to/include-files -L/path/to/libraries prog.c -lctest -o progC++语言: g++ -Wall -I/path/to/include-files -L/path/to/libraries prog2.cpp -lctest -ldl -o prog2参数详解:-I: 指定头文件目录. -L: 指定库目录.-lctest: 调用动态库libctest.so.1.0. 如果在打包so时没有创建第一个符号链接,那么这个参数会导致编译不成功.-ldl: C++编译必须相关知识命令ldd appname 可以查看应用程序所依赖的动态库,运行如下命令:ldd prog
在我的机器输出:
linux-gate.so.1 =&
(0xb80d4000)
libctest.so.1 =& /usr/lib/libctest.so.1 (0xb80be000)
libc.so.6 =& /lib/tls/i686/cmov/libc.so.6 (0xb7f5b000)
/lib/ld-linux.so.2 (0xb80d5000)<font color="# C++开发带class的so//myclass.h#ifndef __MYCLASS_H__#define __MYCLASS_H__class MyClass{public:
MyClass();
/* use virtual otherwise linker will try to perform static linkage */
virtual void DoSomething();private:
int};#endif//myclass.cpp#include "myclass.h"#include &iostream&using namespaceextern "C" MyClass* create_object(){
return new MyC}extern "C" void destroy_object( MyClass* object ){
delete object;}MyClass::MyClass(){
x = 20;}void MyClass::DoSomething(){
cout&&x&&}//class_user.cpp#include &dlfcn.h&#include &iostream&#include "myclass.h"using namespaceint main(int argc, char **argv){
/* on Linux, use "./myclass.so" */
void* handle = dlopen("./myclass.so", RTLD_LAZY);
MyClass* (*create)();
void (*destroy)(MyClass*);
create = (MyClass* (*)())dlsym(handle, "create_object");
destroy = (void (*)(MyClass*))dlsym(handle, "destroy_object");
MyClass* myClass = (MyClass*)create();
myClass-&DoSomething();
destroy( myClass );}编译和运行: g++ -fPIC -shared myclass.cpp -o myclass.so g++ class_user.cpp -ldl -o class_user ./class_user
Remember Me?
&&&&&&&&&&&&&&
[使用Ctrl+Enter键可以直接提交]
272829303112345679101213141516171819202324252628293031123456
阅读排行榜
评论排行榜您的当前位置:&>&&>&&>& > 正文
Ubuntu 14.04 下开启PHP错误提示
  Ubuntu 14.04中,默认的PHP开发环境配置是不提示所有的警告、错误信息的。这对于开发者来说是很痛苦的。在此记录下配置方法,留作以后方便使用。千纸鹤的小编也已找了2种哦,第一种很简单,但是步骤跨度较大,第二种,步骤详细到不能再详细了。大家随便抱走。
  精简版步骤:
  1、修改php配置文件php.ini
复制代码代码如下:  sudo gedit /etc/php5/apache2/php.ini
  把 display_errors = Off 改为 display_errors = On
  把 error_reporting = xxx 改为 error_reporting = E_ALL | E_STRICT
  2、重启apache
复制代码代码如下:  sudo /etc/init.d/apache2 restart
  OK!好好享受吧!
  详细版步骤
  1. 打开php.ini文件。
  以我的ubuntu为例,这个文件在: /etc/php5/apache2 目录下。
  2. 搜索并修改下行,把Off值改成On
复制代码代码如下:  display_errors = Off
  3. 搜索下行
复制代码代码如下:  error_reporting = E_ALL & ~E_NOTICE
  或者搜索:
复制代码代码如下:  error_reporting = E_ALL & ~E_DEPRECATED
  修改为
复制代码代码如下:  error_reporting = E_ALL | E_STRICT
  4. 修改Apache的 httpd.conf,
  以我的 Ubuntu 为例, 这个文件在:/etc/apache2/& 目录下,这是一个空白文件。
  添加以下两行:
复制代码代码如下:  php_flag display_errors
on  php_value error_reporting
  5. 重启Apache,就OK了。
  重启命令:
复制代码代码如下: :sudo /etc/init.d/apache2 restart
  ok! 错误提示成功开启!以上就是Ubuntu下LAMP的PHP错误提示的开启方法。希望能帮到大家,谢谢阅读,请继续关注千纸鹤。
【推荐】下载星空中文网的快捷方式到桌面,以便下次使用。&&下载本文
文章很赞,分享给朋友
12345678910ubuntu下火狐浏览器装FLASHPLAYER插件失败_百度知道
ubuntu下火狐浏览器装FLASHPLAYER插件失败
放到火狐目录下也没用,install_flash_player_10_linux,解压出来也不能安装.gz.tar,install_flash_player_10_linux,不能安装.deb.53的FIERFOX 3
好像有ROOT权限&.baidu。&/zhidao/pic/item/b58f8c5494eef01fb6fe24d8e0fedc0://e.mozilla/firefo下,没有一楼说的flash-plugin/目录.hiphotos.jpg" esrc="/zhidao/wh%3D450%2C600/sign=dd0d88e639dbb6fd250eed223c14872e/b58f8c5494eef01fb6fe24d8e0fedc0.jpg" target="_blank" title="点击查看大图" class="ikqb_img_alink"><img class="ikqb_img" src="http://e.5,试了没起作用.baidu.baidu,有这个/usr/lib/firefox-3://e,别人要我放到/home/用户/,root进去安装也是如图<a href="http,/usr/share/firefox/没有plugins目录.我是32位的&/zhidao/wh%3D600%2C800/sign=5ecc07d91bd5ad6eaaac6cecb1fb15e3/b58f8c5494eef01fb6fe24d8e0fedc0;.hiphotos.3/plugins,是放这吗deb提示无法读取什么标志什么的&
提问者采纳
终端进入deb文件所在目录,就是原来装的flashplayer插件9的更新成10的时候的问题,打dpkg -i XXXXXXXXX,多看看README里面的信息 ----------------------------------------------------------不要双击打开那个deb文件,提示错误信息是什么;目录下的 但是我是见过一个flashplayer插件的bug的.usr&#47,直接运行他看看?,这个解压出来是一个ibflashplayer.gz解压出来的有flashplayer-installer这个文件没?install_flash_player_10_linux.tar.tar?install_flash_player_10_linux,装不上 ------------------------------------------------------------出错信息能复制过来么;flash-plugin/lib&#47,解压放到&#47.so动态库文件的?什么叫不能安装问题描述能清楚点么
提问者评价
我是装那个RPM才行,装好后再按你的dpkg -i XXXXXXXXX.deb,好像命令也执行成功。
其他类似问题
欢迎继续在本平台咨询;myd@ubuntu,如有疑问。希望我的回答对您有所帮助;桌面$sudo cp libflashplayer:~$cd &#39;myd&#47,并解压到桌面上:“myd@usr”您可以在火狐社区了解更多内容;* &#47.i386;桌面$sudo cp -r usr/mozilla&#47.tar:~&#47:myd@ubuntu!
先在Adobe官网下载install_flash_player_11_plugins # [sudo]password for myd:~/lib/usr&#47,并在终端中安装.so /桌面&#39;home/&#47.gz!很高兴为您答疑您好
已回答24623
响应时间&23小时
为您推荐:
其他1条回答
即可,有个xxxxxx,放到/plugins&#47估计你是64位的Ubuntu我是ubuntu9。光这个操作,解压;firefox/share&#47,deb没法装;usr&#47。so 的文件!下载tar包.04(Amd64)
flashplayer的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁Ubuntu14.04安装Caffe:记一个编译问题解决过程 | 自在飞自在飞
Ubuntu14.04安装Caffe:记一个编译问题解决过程 | 自在飞自在飞Ubuntu下Restund服务器搭建_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
Ubuntu下Restund服务器搭建
上传于||文档简介
&&U&#8203;b&#8203;u&#8203;n&#8203;t&#8203;u&#8203;下&#8203;R&#8203;e&#8203;s&#8203;t&#8203;u&#8203;n&#8203;d&#8203;服&#8203;务&#8203;器&#8203;搭&#8203;建
阅读已结束,如果下载本文需要使用
想免费下载本文?
你可能喜欢

我要回帖

更多关于 ubuntu安装出错 的文章

 

随机推荐