读书人

请问小弟我如果想创建一个C++工程使

发布时间: 2012-02-20 21:18:23 作者: rapoo

请教我如果想创建一个C++工程,使在windows和linux unix上都可以编译怎么办?另外linux怎么连数据库呀?
请教我如果想创建一个C++工程,,使在windows和linux unix上都可以编译怎么办?另外linux怎么用C++连Oracle数据库呀?

[解决办法]
通用编译方法如下:


//均支持的 include
#include <stdio.h>
#include <stdarg.h>
#include <sys/stat.h>

#include <fstream>
#include <time.h>
#ifdef agent_windows
#define PATH_CONFIG "..\\cfg\\ "
#define PATH_RUNLOG "..\\log\\ "
#define PATH_STTCDATA "..\\sdata\\ "
#else
#define PATH_CONFIG "../cfg/ "
#define PATH_RUNLOG "../log/ "
#define PATH_STTCDATA "../sdata/ "
#endif//agent_windows

//有差异的 include
#ifdef agent_windows

typedef enum log_level_t {
CR = 0,
ER,
WA,
TR,
ST
} log_level_t;

#define WIN32_LEAN_AND_MEAN// Exclude rarely-used stuff from Windows headers
#define _WIN32_WINNT 0x0400

#include <windows.h>
#include <sstream>
#include <conio.h>
#include <tchar.h>
#include <pdh.h>


#define SokErrorNo h_errno

#define MUTEX_LOCKCRITICAL_SECTION
#define MUTEX_LOCK_INIT(lock)InitializeCriticalSection(lock)
#define MUTEX_LOCK_DESTROY(lock)DeleteCriticalSection(lock)
#define LOCK EnterCriticalSection
#define UNLOCK LeaveCriticalSection
#define TRYLOCK TryEnterCriticalSection
#define SLEEP(nMill)Sleep(nMill);
#define MSLEEP(nMill)Sleep(nMill);
#define SLASHC '\\ '
#define SLASHSTR "\\ "

typedef struct _stat sSTAT;
#define STAT_stat

#include "winsock2.h "
#pragma comment(lib, "ws2_32.lib ")

#else

#ifndef _UNIX_
#define _UNIX_
#endif

typedef int BOOL;

#ifndef FALSE
#define FALSE 0
#endif

#ifndef TRUE
#define TRUE 1
#endif


typedef unsigned int UINT;

typedef unsigned long DWORD;
typedef void* HANDLE;
typedef void* LPVOID;
typedef const char *LPCSTR, *PCSTR;
typedef LPCSTR LPCTSTR;

typedef unsigned int SOCKET;

#include <sys/types.h>
#include <sys/ipc.h>
//#include <sys/ddi.h>
#include <sys/msg.h>
#include <unistd.h>
#include <errno.h>
#include <pthread.h>
#include <string>
#include <iostream>
#include <arpa/inet.h>
#include <semaphore.h>
#include <sys/socket.h>
#include <signal.h>
#include "ConfigFile.h "

#include <applib.h>
#include <bsclib.h>


#define INVALID_SOCKET (SOCKET)(~0)
#define SOCKET_ERROR (-1)
#defineclosesocket close
#define SokErrorNo errno

#define MUTEX_LOCKpthread_mutex_t
#define MUTEX_LOCK_INIT(lock)pthread_mutex_init(lock,NULL)
#define MUTEX_LOCK_DESTROY(lock)pthread_mutex_destroy(lock)
#define LOCK pthread_mutex_lock
#define UNLOCK pthread_mutex_unlock
#define TRYLOCK(lock) (pthread_mutex_trylock(lock) == 0)
#define SLEEP(nMill)sleep((int)nMill/1000);
#define MSLEEP(nMill)usleep(nMill*1000);
#define SLASHC '/ '
#define SLASHSTR "/ "

typedef struct stat sSTAT;
#define STATstat
#endif//agent_windows

[解决办法]
用跨平台的库:wxWidget, QT, ACE等等!
[解决办法]
LS + LSLS
[解决办法]
可以使用ACE的库,QT也好.然后写成一个makefile在LINUX下编译一把就可以两个平台一起跑了

读书人网 >C++

热点推荐