在openSUSE操作系统下简单编程指南
在openSUSE操作系统下简单编程指南
一、安装gcc和make1、正常安装之后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.dll
- class AE_DEMO_ENTRY CTest
- {
- public:
- CTest();
- virtual ~CTest();
- public:
- int Add(int a, int b);
- protected:
- int m_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 variable
- AE_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 definition
- CTest::CTest()
- {
- }
- CTest::~CTest()
- {
- }
- int CTest::Add(int a, int b)
- {
- return (a + b);
- }
|
评论暂时关闭