在opensuse操作系统下简单编程指南
来源:互联网 发布:好一点的耳环品牌 知乎 编辑:程序博客网 时间:2024/06/07 12:17
一、安装gcc和make
1、正常安装之后opensuse操作系统没有安装gcc和make,需要自己安装。首先从“计算机”开始选择“安装软件”。
2、从软件包管理器选择程序“programming”,从右边栏中找到 gcc和make,点击右下角应用和安装即可。
二、用户环境变量设置
用root用户登录系统,进行如下相应的操作。Windows环境变量比较简单这里就不再描述了。
A、编辑/etc/profile,增加自定义的环境变量:
FEPHOME=/openSuse3000/fep
LD_LIBRARY_PATH=$ FEPHOME/bin:$ LD_LIBRARY_PATH
export FEPHOME LD_LIBRARY_PATH
B、生效命令Source
#Source /etc/profile
C、查看是否生效
#echo $FEPHOME
D、查看环境变量
#env
三、动态链接库范例
可以使用VC++6.0生成一个动态链接库libdemo,libdemo目录下包含inc、src、unix和win32,其中inc目录存放*.h文件,src目录存放*.c/*.cpp文件,unix目录存放MakeFile,win32存放vc++6.0的*.dsp和*.dsw等。
Linux
/ openSuse3000/fep
|_bin
|_lib
|_code
|_include
|_test_sys
libdemo
|_inc
|_src
|_uinx
|_win32
testdemo
|_inc
|_src
|_uinx
|_win32
/FEPDebug
|_libdemo
|_testdemo
libdemo存放stdafx.o和demo.o目标文件;testdemo存放stdafx.o和testdemo.o目标文件。
#stdafx.h// stdafx.h : include file for standard system include files,// or project specific include files that are used frequently, but// are changed infrequently//#if !defined(AFX_STDAFX_H__E5CE9468_AAF9_46A6_979B_9C125F6E9D00__INCLUDED_)#define AFX_STDAFX_H__E5CE9468_AAF9_46A6_979B_9C125F6E9D00__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000#define WIN32_LEAN_AND_MEAN// Exclude rarely-used stuff from Windows headers#include <stdio.h>// TODO: reference additional headers your program requires here//{{AFX_INSERT_LOCATION}}// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_STDAFX_H__E5CE9468_AAF9_46A6_979B_9C125F6E9D00__INCLUDED_)#stdafx.cpp// stdafx.cpp : source file that includes just the standard includes//libdemo.pch will be the pre-compiled header//stdafx.obj will contain the pre-compiled type information#include "stdafx.h"// TODO: reference any additional headers you need in STDAFX.H// and not in this file#demo.h#ifndef _DEMO_H_#define _DEMO_H_// The following ifdef block is the standard way of creating macros which make exporting // from a DLL simpler. All files within this DLL are compiled with the AE_DEMO_EXPORTS// symbol defined on the command line. this symbol should not be defined on any project// that uses this DLL. This way any other project whose source files include this file see // AE_DEMO_ENTRY functions as being imported from a DLL, wheras this DLL sees symbols// defined with this macro as being exported.#ifdef WIN32#ifdef AE_DEMO_EXPORTS#define AE_DEMO_ENTRY __declspec(dllexport)#else#define AE_DEMO_ENTRY __declspec(dllimport)#endif#else#define AE_DEMO_ENTRY#endif// This class is exported from the libdemo.dllclass AE_DEMO_ENTRY CTest {public:CTest();virtual ~CTest();public:int Add(int a, int b);protected:intm_nCount;};extern AE_DEMO_ENTRY int nTest;AE_DEMO_ENTRY int fnTest();#endif // _DEMO_H_#demo.cpp#include "stdafx.h"#include "demo.h"// This is an example of an exported variableAE_DEMO_ENTRY int nTest = 0x64;// This is an example of an exported function.AE_DEMO_ENTRY int fnTest(){return 64;}// This is the constructor of a class that has been exported.// see demo.h for the class definitionCTest::CTest(){ }CTest::~CTest(){ }int CTest::Add(int a, int b){return (a + b);}
四、测试动态链接库范例
// testdemo.cpp : Defines the entry point for the console application.//// 把demo.h拷贝至$(FEPHOME)/include目录中.#include "stdafx.h"#include "demo.h"int main(int argc, char* argv[]){CTest test;int nSum = test.Add(1, 2);printf("a=1,b=2,sum=%d\n", nSum);printf("nTest=%d\n", nTest);printf("int fnTest() return %d\n", fnTest());return 0;}
执行结果:
linux-qf6g:/openSusu3000/fep/bin # ./testdemo
a=1,b=2,sum=3
nTest=100
int fnTest() return 64
五、MakeFile编写
makefile_linux
############################################################################## Title: makefile_linux(opensuse 11.0)# Author: liuxuezong# Project: PRJNAME# Generated by 2011.08.31 14:56#############################################################################OBJDIR= $(PRJOUT)/$(PRJNAME)DLLDIR= $(FEPHOME)/binBINDIR= $(FEPHOME)/binLIBDIR= $(FEPHOME)/libCODEDIR= $(FEPHOME)/codeINCPATH= -I../inc -I$(FEPHOME)/code/include####### Compiler, tools and optionsAR= ar CXX= g++CC= cc LD= g++MAKE= makeGM= gmakeYACC= yaccLEX= lexTAR = tar -cfCOMPRESS = gzip -9fCOPY = cp -fSED = sedCOPY_FILE = $(COPY)COPY_DIR = $(COPY) -RSTRIP = INSTALL_FILE = $(COPY_FILE)INSTALL_DIR = $(COPY_DIR)INSTALL_PROGRAM = $(COPY_FILE)DEL_FILE = rm -fSYMLINK = ln -f -sDEL_DIR = rmdirMOVE = mv -fCHK_DIR_EXISTS= test -dMKDIR = mkdir -p####### Compiler, flags definitionsARFLAGS = -vrCFLAGS = -g CXXFLAGS = -c -fpic -w -gLDCFLAGS = -G -z defs -lsocket -lnsl -ldl LDCXXFLAGS = -shared CLDFLAGS = -gCXXLDFLAGS = -g -GBINLIB = -lcTHREAD_LIB = -lpthreadSOCKET_LIB = -lsocket -lnslDYLOAD_LIB = -ldl
libdemo的Makefile
PRJNAME= libdemoPRJOUT= /FEPDebuginclude $(FEPHOME)/code/include/makefile_linux####### FilesSRCDIR=../srcSOURCES = stdafx.cpp \ demo.cppOBJECTS = $(OBJDIR)/stdafx.o \ $(OBJDIR)/demo.o TARGET= $(DLLDIR)/$(PRJNAME).soTARGETA = $(LIBDIR)/$(PRJNAME).a####### Build rulesall: obj_dir $(TARGET) $(TARGETA)obj_dir:@$(CHK_DIR_EXISTS) $(OBJDIR) || $(MKDIR) $(OBJDIR)$(TARGET): $(OBJECTS) $(LD) $(LDCXXFLAGS) -o $@ $(OBJECTS) $(CXXLIB)$(TARGETA): $(OBJECTS) $(AR) $(ARFLAGS) $@ $(OBJECTS)####### Include file dependenciesdepend:@(mkdepend -p$(OBJDIR)/ -o.o $(INCPATH) $(SOURCES))>/dev/null 2>&1@rm -f makefile.bakclean:rm -f $(OBJECTS)rm -f $(TARGET)rm -f $(TARGETA)####### Compile$(OBJDIR)/stdafx.o: $(SRCDIR)/stdafx.cpp$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $?$(OBJDIR)/demo.o: $(SRCDIR)/demo.cpp$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $?# DO NOT DELETE THIS LINE -- make depend depends on it.
testdemo的Makefile
PRJNAME= testdemoPRJOUT= /FEPDebuginclude $(FEPHOME)/code/include/makefile_linux####### FilesSRCDIR=../srcSOURCES = stdafx.cpp \ testdemo.cppOBJECTS = $(OBJDIR)/stdafx.o \ $(OBJDIR)/testdemo.o FEPLIB = -L$(DLLDIR) -ldemo OUTBIN = ${BINDIR}/testdemo####### Build rulesall: obj_dir $(OUTBIN)obj_dir:@$(CHK_DIR_EXISTS) $(OBJDIR) || $(MKDIR) $(OBJDIR)$(OUTBIN): $(OBJECTS) $(CXX) -o $@ $(OBJECTS) $(CXXLIB) $(FEPLIB) $(THREAD_LIB) $(DYLOAD_LIB)####### Include file dependenciesdepend:@(mkdepend -p$(OBJDIR)/ -o.o $(INCPATH) $(SOURCES))>/dev/null 2>&1@rm -f makefile.bakclean:rm -f $(OBJECTS)rm -f $(OUTBIN)####### Compile$(OBJDIR)/stdafx.o: $(SRCDIR)/stdafx.cpp$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $?$(OBJDIR)/testdemo.o: $(SRCDIR)/testdemo.cpp$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $?# DO NOT DELETE THIS LINE -- make depend depends on it.
- 在opensuse操作系统下简单编程指南
- 在openSUSE-11.1 linux环境下Redis的安装和简单测试
- 在grub2下通过硬盘安装opensuse
- Docker 在 openSUSE 下的安装、使用
- altera在opensuse下的安装
- NetBSD操作系统在VMware下的安装指南
- 操作系统OpenSUSE 12.3安装
- posix 操作系统串口编程指南
- POSIX操作系统串行编程指南
- 在虚拟机下运行自制的简单“操作系统”
- 在Linux操作系统下共享库编程的方法介绍
- tomcat在opensuse下开机自启失败的原因
- lampp 在opensuse下不能起動mysql
- openSUSE: 在Linux下安装Wireshark,经典协议分析器
- openSUSE 11.4 liveCD 在 WIN7 下使用 U盘 安装
- 在openSUSE Linux下升级firefox的方法
- vsftpd在opensuse环境下建立ftp服务器
- 在openSUSE 13.1下安装卸载openjdk以及Oracle JDK
- CentOS 修改IP地址, DNS, 网关
- 向数据库中导入数据dmp,出现数据为0行的表将导入不进去
- 多线程编程(一):线程创建和退出
- 如何去掉点击链接时周围的虚线框
- oracle平面文件卸载数据
- 在opensuse操作系统下简单编程指南
- 谈谈对APC的一点理解
- 加锁解锁PHP实现
- pthread_once 和 pthread_key
- Moodle(2.1+)新搭建完毕后要做的事情(2.3.1+更新)
- Java常用类库(一)
- int A[nSize],其中隐藏着若干0,其余非0整数,写一个函数int Func(int* A, int nSize),使A把0移至后面,非0整数移至后面
- ComboBox没有到具体一个item的Tag属性。
- EXCEL 截取一段,做除法运算,精确两位小数