在openSUSE操作系统下简单编程指南


一、安装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目标文件。

  1. #stdafx.h   
  2. // stdafx.h : include file for standard system include files,   
  3. //  or project specific include files that are used frequently, but   
  4. //      are changed infrequently   
  5. //   
  6.   
  7. #if !defined(AFX_STDAFX_H__E5CE9468_AAF9_46A6_979B_9C125F6E9D00__INCLUDED_)   
  8. #define AFX_STDAFX_H__E5CE9468_AAF9_46A6_979B_9C125F6E9D00__INCLUDED_   
  9.   
  10. #if _MSC_VER > 1000   
  11. #pragma once   
  12. #endif // _MSC_VER > 1000   
  13.   
  14. #define WIN32_LEAN_AND_MEAN     // Exclude rarely-used stuff from Windows headers   
  15.   
  16. #include <stdio.h>   
  17.   
  18. // TODO: reference additional headers your program requires here   
  19.   
  20. //{{AFX_INSERT_LOCATION}}   
  21. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.   
  22.   
  23. #endif // !defined(AFX_STDAFX_H__E5CE9468_AAF9_46A6_979B_9C125F6E9D00__INCLUDED_)   
  24.   
  25. #stdafx.cpp   
  26. // stdafx.cpp : source file that includes just the standard includes   
  27. //  libdemo.pch will be the pre-compiled header   
  28. //  stdafx.obj will contain the pre-compiled type information   
  29.   
  30. #include "stdafx.h"   
  31.   
  32. // TODO: reference any additional headers you need in STDAFX.H   
  33. // and not in this file   
  34.   
  35. #demo.h   
  36. #ifndef _DEMO_H_   
  37. #define _DEMO_H_   
  38.   
  39. // The following ifdef block is the standard way of creating macros which make exporting    
  40. // from a DLL simpler. All files within this DLL are compiled with the AE_DEMO_EXPORTS   
  41. // symbol defined on the command line. this symbol should not be defined on any project   
  42. // that uses this DLL. This way any other project whose source files include this file see    
  43. // AE_DEMO_ENTRY functions as being imported from a DLL, wheras this DLL sees symbols   
  44. // defined with this macro as being exported.   
  45. #ifdef WIN32   
  46. #ifdef AE_DEMO_EXPORTS   
  47. #define AE_DEMO_ENTRY __declspec(dllexport)   
  48. #else   
  49. #define AE_DEMO_ENTRY __declspec(dllimport)   
  50. #endif   
  51. #else   
  52. #define AE_DEMO_ENTRY   
  53. #endif   
  54.   
  55. // This class is exported from the libdemo.dll   
  56. class AE_DEMO_ENTRY CTest   
  57. {  
  58. public:  
  59.     CTest();  
  60.     virtual ~CTest();  
  61. public:  
  62.     int Add(int a, int b);  
  63. protected:  
  64.     int m_nCount;  
  65. };  
  66.   
  67. extern AE_DEMO_ENTRY int nTest;  
  68.   
  69. AE_DEMO_ENTRY int fnTest();  
  70.   
  71. #endif // _DEMO_H_   
  72.   
  73. #demo.cpp   
  74. #include "stdafx.h"   
  75. #include "demo.h"   
  76.   
  77. // This is an example of an exported variable   
  78. AE_DEMO_ENTRY int nTest = 0x64;  
  79.   
  80. // This is an example of an exported function.   
  81. AE_DEMO_ENTRY int fnTest()  
  82. {  
  83.     return 64;  
  84. }  
  85.   
  86. // This is the constructor of a class that has been exported.   
  87. // see demo.h for the class definition   
  88. CTest::CTest()  
  89. {   
  90. }  
  91.   
  92. CTest::~CTest()  
  93. {   
  94. }  
  95.   
  96. int CTest::Add(int a, int b)  
  97. {  
  98.     return (a + b);  
  99. }  
  • 1
  • 2
  • 下一页

相关内容