1. Gcc安装
1.1. 下载
1.2. 解压缩
比如文件名为:gcc-ia64-4.5.3.depot.gz
gunzip gcc-ia64-4.5.3.depot.gz
1.3. 安装
使用root用户登陆
swinstall -s <FILE_NAME> #注意路径为全路径
在要安装的项目前作上安装标记。在Action菜单中有一个菜单项mark install可以对当前选中的项目作安装标记;
选中好要安装的项目后,继续执行Action菜单中的install命令,安装将会开始,并会提示安装百分比。
安装完毕,选择File菜单中的exit命令退出。
查看安装日志:/var/adm/sw/swagent.log
1.4. 验证安装
whereis gcc
ajkdb#[/]whereis gcc
gcc: /opt/hp-gcc-4.5.3/bin/gcc /opt/hp-gcc-4.5.3/share/man/man1/gcc.1
man gcc
1.5. 其他
卸载:swremove,使用示例
1、以 root 用户登录。 2、在命令行上输入: swremove显示“SD 除去软件选择”面板。 3、选择待卸载的所有 Tivoli Access Manager for Operating Systems 软件包。 4、在“操作”菜单中,选择标记为除去。 5、在“操作”菜单中,选择除去(分析)。显示“除去(分析)”弹出面板。当状态为“就绪”时,请单击确定。 6、在确认弹出面板中,单击是。显示“除去”面板。 7、当状态为“完成”时,单击完成。 8、关闭“SD 除去软件选择”面板。 9、当卸载过程完成时重新引导。 |
有时候安装完成,无法man,需要手工处理下,根据evn里面的MANPATH做手工ln
ajkdb#[/opt]ln -s /opt/hp-gcc-4.5.3 hp-gcc
ajkdb#[/opt/hp-gcc]ln -s /opt/hp-gcc/share/man man
1.6. 测试
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
int main(int argc, char *argv[])
{
char str[1000],str2[1000];
int i=0;
time_t timep;
printf("字符串处理测试:\n");
memset(str,'\0',1000);
strcpy(str,"\t12345678 ");
strcat(str,"中华人民共和国 ");
strcat(str,"abcdefg");
sprintf(str2,"%s, length=%d\n",str,sizeof(str));
printf(str2);
printf("1-10循环测试:\n");
for(i=0; i<10; i++)
printf("\t%d\n",i);
printf("类型转换测试:\n");
memset(str,'\0',1000);
strcpy(str,"100");
printf("\t%s:%d\n",str,atoi(str));
printf("数学处理测试:\n");
printf("\tabs(-5)=%d, ceil(74.12)=%.0f, log10(5.0)=%f\n",abs(-5),ceil(74.12),log10(5.0));
printf("字符类型测试:\n");
memset(str,'\0',1000);
strcpy(str,"1 2 a b * C");
for(i=0;str[i]!=0;i++)
{
//printf("-%c- ",str[i]);
if(isdigit(str[i])) {printf("\"%c\" is an digit character\n",str[i]);continue;}
if(islower(str[i])) {printf("\"%c\" is an lower character\n",str[i]);continue;}
if(isspace(str[i])) {printf("\"%c\" is an space character\n",str[i]);continue;}
else printf("\"%c\" is an other character\n",str[i]);
}
printf("时间测试:\n");
time(&timep);
printf("%s",asctime(gmtime(&timep)));
//system("PAUSE");
return 0;
}
编译:gcc gccTest.c -o gccTest
执行:./gccTest
2. Sqc编译环境配置
2.1. 准备工作
l 建立公共目录:public,并将属组给实例用户
mkdir public
chown hhbiinst:biadm public
l 拷贝文件:至public目录
cp /opt/IBM/db2/V9.5/samples/c/embprep /hhbi/public
编写测试文件,至目录/hhbi/public/temp中
#define PRO_NAME "sqcTest"
EXEC SQL INCLUDE SQLCA;
EXEC SQL BEGIN DECLARE SECTION;
char SrcTab1[50];
char TaskID[50];
char exe_sql[10000];
EXEC SQL END DECLARE SECTION;
int main(int argc, char *argv[])
{
memset(SrcTab1,'\0',50);
memset(TaskID,'\0',9);
memset(exe_sql,'\0',10000);
printf("connect db....\n");
EXEC SQL connect to hhbidb;
if(sqlca.sqlcode<0)
{
printf("sqlca.sqlcode=%d\n",sqlca.sqlcode);
}
EXEC SQL VALUES(current date) INTO :TaskID;
if(sqlca.sqlcode<0)
{
printf("sqlca.sqlcode=%d\n",sqlca.sqlcode);
}
printf("task_id: %s\n",TaskID);
printf("create table sqc_test\n");
EXEC SQL create table sqc_test (id int,name char(5));
if(sqlca.sqlcode<0)
{
printf("sqlca.sqlcode=%d\n",sqlca.sqlcode);
}
EXEC SQL connect reset;
}
2.2. 手工编译测试
测试是否可以正确预编译sqc文件
Usage: embprep <prog_name> [ <db_name> [ <userid> <password> ]]
在temp目录中执行: ../embprep sqcTest hhbidb
结果如下,生成bnd与c文件,代表成功:
$ ../embprep sqcTest hhbidb
Database Connection Information
Database server = DB2/HPUX-IA64 9.5.5
SQL authorization ID = HHBIINST
Local database alias = HHBIDB
LINE MESSAGES FOR sqlTest.sqc
------ --------------------------------------------------------------------
SQL0060W The "C" precompiler is in progress.
SQL0091W Precompilation or binding was ended with "0"
errors and "0" warnings.
LINE MESSAGES FOR sqcTest.bnd
------ --------------------------------------------------------------------
SQL0061W The binder is in progress.
SQL0091N Binding was ended with "0" errors and "0" warnings.
DB20000I The SQL command completed successfully.
DB20000I The TERMINATE command completed successfully.
$
使用命令db2 list packages查看package绑定情况,应该已经存在包SQCTEST
编译c文件为可执行文件:
常见错误1:
$ gcc -mlp64 -I /db2home/hhbiinst/sqllib/include -L /db2home/hhbiinst/sqllib/lib -o sqcTest sqcTest.c
ld: Unsatisfied symbol "sqlasetdata" in file /var/tmp//cckn5j28.o
ld: Unsatisfied symbol "sqlastrt" in file /var/tmp//cckn5j28.o
ld: Unsatisfied symbol "sqlastop" in file /var/tmp//cckn5j28.o
ld: Unsatisfied symbol "sqlaaloc" in file /var/tmp//cckn5j28.o
ld: Unsatisfied symbol "sqlacall" in file /var/tmp//cckn5j28.o
5 errors.
collect2: ld returned 1 exit status
为没有指定:-ldb2 -ldb2apie
常见错误2:
$ gcc -I /db2home/hhbiinst/sqllib/include -ldb2 -ldb2apie -L /db2home/hhbiinst/sqllib/lib -o sqcTest sqcTest.c
ld: Mismatched ABI for -ldb2, found /db2home/hhbiinst/sqllib/lib/libdb2.so
Fatal error.
collect2: ld returned 1 exit status
错误原因:
gcc默认为32位,所以此处错误为link数据库DB2的so文件出错,需要显式指定64参数,增加参数:-mlp64
执行:
$ gcc -mlp64 -I /db2home/hhbiinst/sqllib/include -ldb2 -ldb2apie -L /db2home/hhbiinst/sqllib/lib -o sqcTest sqcTest.c
成功!