| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1501 人关注过本帖
标题:[求助]请问c程序可以做成独立于tc环境的可执行文件吗?
只看楼主 加入收藏
忧郁的风
Rank: 1
等 级:新手上路
帖 子:65
专家分:0
注 册:2004-11-1
收藏
 问题点数:0 回复次数:10 
[求助]请问c程序可以做成独立于tc环境的可执行文件吗?
小弟最近做了个小程序,想把它做成可独立于tc环境的可执行文件或是作成一个安装文件,但不知道怎么做,哪位高手知道的话请指点一二,小弟不胜感激!
搜索更多相关主题的帖子: 环境 文件 
2005-04-07 17:11
aakissyou
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2005-3-30
收藏
得分:0 
WIN-TC可以!别的编译器好多都可以的生成.EXE文件

2005-04-07 17:16
空前
Rank: 1
等 级:新手上路
帖 子:1146
专家分:0
注 册:2004-5-11
收藏
得分:0 
在TC目录下面找,就有一个与你的源代码文件名相同的。exe文件!

这个就是,有的放在out目录中!

2005-04-07 19:40
crazip
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2005-4-4
收藏
得分:0 
我觉得凡是exe不就可以独立于tc执行吗

狂热
2005-04-07 21:02
忧郁的风
Rank: 1
等 级:新手上路
帖 子:65
专家分:0
注 册:2004-11-1
收藏
得分:0 
但我试过将.exe文件复制到tc外执行,但好想不行.
请问有其他办法吗?

轻轻的我走了,正如我轻轻的来,轻轻的我挥一挥衣袖,轻轻的抹去我留下的痕迹------风过无痕
2005-04-11 17:13
ChenMo
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:3
帖 子:481
专家分:10
注 册:2004-4-8
收藏
得分:0 
当C程序在TC下被编译及链接后,便是独立于开发环境的可执行文件。
若如您所说,可说明路径问题是其中一个原因,这视乎于你所写的程序是否关系到此类情况,
如程序里的路径是否为绝对的,如: D:\TSoft\Filename.exe,这将是一个无法改变的路径,
每个使用该程序的人并不一定就装在D盘。
假设程序的工作目录就是 D:\TSoft
若 Filename.exe 被移动,则必然发生无法找到的错误。

对此问题,可以使用 getcwd() 函数来取得当前工作目录,然后读取相应的文件。

此类问题在初学者身上出现十分频繁,除上述情况外,还有类似的便是操作系统的系统路径,
如前面所说,并非每个人正在使用的操作系统都是在 C 盘的。
TC下解决该问题可以使用 main() 函数的参数便可获得。
main() 函数的参数一共是三个,常使用的是前两个,如 main(int argc,char *argv[])
而第三个参数,如 env 是当前程序的环境变量(也可以使用 getenv 函数取得)。

若楼主的原因不在于此,且因你并没有提供源代码,难以对症下药,

欢迎加入 MVC 技术讨论群(新群:90093426)
2005-04-11 17:39
忧郁的风
Rank: 1
等 级:新手上路
帖 子:65
专家分:0
注 册:2004-11-1
收藏
得分:0 

就是这个程序了 是个时钟程序,画出一个钟表,调用系统当前时间,使钟表与系统时间同步,并在钟表下面显示当前时间 #include <graphics.h> #include <time.h> #include <stdio.h> #include <math.h> #include <stdlib.h> #include <conio.h> #include <dos.h>

main() { void minutepoint(int,int,int); void pointer(int x,int y,int r); void watchface(int,int,int); void drawcircle(int,int,int,int);

int gdriver=DETECT,gmode,errorcode; int x,y,r=60;

initgraph(&gdriver,&gmode,"");/*initialize the graph*/ errorcode=graphresult(); if(errorcode!=grOk) /*the graph initialization failed*/ { printf("Graphics error:%s\n",grapherrormsg(errorcode)); printf("Press any key to terminate the program......"); getch(); exit(1); } /*end if*/

x=getmaxx()/2; /*set the x coordinate of the circle*/ y=getmaxy()/2; /*set the y coordinate of the circle*/

setbkcolor(LIGHTGRAY); /* set the backgroud color*/

setcolor(YELLOW); outtextxy(x-r-30,y+r+50,"press any key to quit......"); watchface(x,y,r); pointer(x,y,r); } /*end main*/

void drawcircle(int x,int y,int r,int color) { setcolor(color); /*set the circle's color*/ circle(x,y,r); setfillstyle(1,color); floodfill(x,y,color); } /*end drawcircle*/

/*the following function is to draw the hour graduations*/ void hourpoint(int x,int y,int r) { int r0=r-10,i; /*r-r0 is the length of the hour graduations*/ double PI=3.1415927; double temp1=0,temp2=0;

for(i=0;i<12;i++) { temp1=cos(i*PI/6); temp2=sin(i*PI/6);

/*draw the hour graduations*/ line(x+floor(r*temp1),y-floor(r*temp2),x+floor(r0*temp1),y-floor(r0*temp2)); } /*end for*/ } /*end hourpoint*/

/*the following functiong is to draw the minute graduations*/ void minutepoint(int x,int y,int r) { int r0=r-5,i; /*r-r0 is the length of the minute graduations*/ double PI=3.1415927,temp1,temp2;

for(i=0;i<60;i++) if(i%5!=0) { temp1=cos(i*PI/30); temp2=sin(i*PI/30);

/*draw the minute graduations*/ line(x+floor(r*temp1),y-floor(r*temp2),x+floor(r0*temp1),y-floor(r0*temp2)); } /*end if*/ } /*end minutepoint*/

/*the following function is to draw the face of the clock*/ void watchface(int x,int y,int r) { drawcircle(x,y,r+10,YELLOW); drawcircle(x,y,r,LIGHTBLUE);

setcolor(YELLOW); /*set color of the hour graduations and the minute graduations*/

hourpoint(x,y,r); minutepoint(x,y,r); } /*end watchface*/

/*the following function is to draw the hourpointer,minutepointer,secondpointer*/ void pointer(int x,int y,int r) { /*len is the secondpointer's length*/ /*mlen is the minutepointer's length*/ /*hlen is the hourpointer's length*/ /*counter is to count the current minute, the hourpointer will move forward a graduation every 12 minutes*/

int len=r-15,mlen=r-30,hlen=r-45,i,j,k,counter=0; double PI=3.1415927; struct time t,t1,t2; time_t t0; int *buffer1,size1;

/*apply space to store the image of current time*/ time(&t0); size1=imagesize(x-r-30,y+r+30,x-r+strlen(ctime(&t0)),y+r+40); buffer1=(int *) malloc (size1); if(!buffer1) { printf("Can't apply spaces to store the image!\n"); printf("Press any key to terminate the program......"); getch(); } /*end if*/

settextstyle(0,0,1);/*set the text property*/

gettime(&t); counter=t.ti_min/12; /*calculate current minute is how many times of 12*/ k=(t.ti_hour%12)*5+counter;/*set the hourpointer's initial position*/

for(;;) /*the circulation of the hourpointer*/ for(j=t.ti_min;j<t.ti_min+60;) /*the circulation of the minutepointer*/ { if(t.ti_min%12==0) /*redraw the hour pointer*/ { setcolor(LIGHTBLUE); line(x,y,x+floor(hlen*cos(k*PI/30)),y-floor(hlen*sin(k*PI/30))); setcolor(YELLOW); line(x,y,x+floor(hlen*cos(k*PI/30)),y-floor(hlen*sin(++k*PI/30))); } /*end if*/ for(i=t.ti_sec;i<t.ti_sec+60;)/*the circulation of the secondpointer*/ { gettime(&t1); while(1) { if(kbhit()) exit(0);/*press any key to exit*/ gettime(&t2); if(t2.ti_sec-t1.ti_sec==1||t2.ti_sec-t1.ti_sec==-59) break; } /*end while*/

/*draw the minutepointer*/ line(x,y,x+floor(mlen*cos((15-j)*PI/30)),y-floor(mlen*sin((15-j)*PI/30)));

if(t2.ti_sec-t1.ti_sec==-59) /*redraw the minute pointer every 60 seconds*/ { setcolor(LIGHTBLUE); line(x,y,x+floor(mlen*cos((15-j)*PI/30)),y-floor(mlen*sin((15-j)*PI/30))); setcolor(YELLOW); line(x,y,x+floor(mlen*cos((15-j)*PI/30)),y-floor(mlen*sin((15-++j)*PI/30))); } /*end if*/

/*redraw the hourpointer*/ line(x,y,x+floor(hlen*cos((15-k)*PI/30)),y-floor(hlen*sin((15-k)*PI/30)));

/*redraw the secondpointer*/ setcolor(LIGHTBLUE); line(x,y,x+floor(len*cos((15-i)*PI/30)),y-floor(len*sin((15-i)*PI/30))); setcolor(YELLOW); line(x,y,x+floor(len*cos((15-i)*PI/30)),y-floor(len*sin((15-++i)*PI/30)));

/*show the current time in text form*/ putimage(x-r-30,y+r+30,buffer1,1);/*put the current time*/ time(&t0);/*get the current time*/ outtextxy(x-r-30,y+r+30,ctime(&t0)); /*get image of the current time*/ getimage(x-r-30,y+r+30,x-r-30+size1,y+r+40,buffer1); } /*end for*/ } /*end for*/ } /*end pointer*/ 


轻轻的我走了,正如我轻轻的来,轻轻的我挥一挥衣袖,轻轻的抹去我留下的痕迹------风过无痕
2005-04-11 17:45
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
收藏
得分:0 
因为你调用的graphics.h图形函数库,所以你的EXE文件必须要和BGI(图形驱动文件)放在一起

给你一个笨点的解决方法,把TC下所有BGI为后缀名的文件和你的EXE放在一起就可以了.

淘宝杜琨
2005-04-11 17:55
空前
Rank: 1
等 级:新手上路
帖 子:1146
专家分:0
注 册:2004-5-11
收藏
得分:0 
厉害!

2005-04-11 18:45
ChenMo
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:3
帖 子:481
专家分:10
注 册:2004-4-8
收藏
得分:0 
若确定是图形库的问题,则解决方法有两种:
其一是8楼 神vLinux飘飘 的方法;然而明显地看到此种方法的弊端——就是增加了加载代码,且可执行文件必须将其作为可执行文件的附随文件;
其二是将程序所使用的图形库启动程序文件及字体集转换为目标文件,再将其连接直接嵌入到可执行文件中,作为可执行文件的一部分。使用这种方法可弥补了第一种方法的缺点,但是其缺点(也是必然地)加长了可执行文件的大小(长度)。这应该也是楼主所希望的方法。

方法二所述的制作步骤如下:
1.将驱动程序和字体文件转换为目标文件(*.OBJ)。使用TC自带的 BGIOBJ.EXE 程序即可实现。其命令行方式如下:
       BGIOBJ &lt;参数:驱动程序或字体文件源文件&gt;
创建的目标文件名与命令行输入的参数相同,扩展名是 .OBJ。

2.连接该目标文件直接嵌入到可执行文件中。

若需要范例的朋友请提供 E-mail 。

欢迎加入 MVC 技术讨论群(新群:90093426)
2005-04-12 13:01
快速回复:[求助]请问c程序可以做成独立于tc环境的可执行文件吗?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012353 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved