问题描述
实际上,我必须调试一个旧的C程序。我是C编程的新手,运行此程序时遇到奇怪的行为。该程序使用PCRE,这是一个移植到Windows的正则表达式库(我从http://gnuwin32.sourceforge.net/downlinks/pcre-lib-zip.php获得了“开发人员文件”),但是当程序尝试使用该库中的函数时,甚至没有调用main方法。 我将其范围缩小为一个简单的HelloWorld,如下所示:
#include <stdio.h>
#include <regex.h>
int main(int argc,char *argv[]) {
printf("Hello,world!\n");
regex_t re;
regcomp(&re,"sam",0);
return 0;
}
该程序成功编译并链接。
19:55:32 **** Rebuild of configuration Debug for project Test ****
Info: Internal Builder is used for build
gcc "-ID:\\Cpp\\pcre\\include" -O0 -g3 -Wall -c -fmessage-length=0 -o Hello.o "..\\Hello.c"
gcc "-LD:\\Cpp\\pcre\\lib" -o Test.exe Hello.o -lpcre -lpcreposix
19:55:35 Build Finished. 0 errors,0 warnings. (took 3s.750ms)
执行时返回0,即使printf调用是主函数的第一个调用,也不打印任何内容
#include <stdio.h>
#include <regex.h>
int main(int argc,world!\n");
regex_t re;
//regcomp(&re,0);
return 0;
}
然后编译并链接
19:57:19 **** Rebuild of configuration Debug for project Test ****
Info: Internal Builder is used for build
gcc "-ID:\\Cpp\\pcre\\include" -O0 -g3 -Wall -c -fmessage-length=0 -o Hello.o "..\\Hello.c"
..\Hello.c: In function 'main':
..\Hello.c:12:10: warning: unused variable 're' [-Wunused-variable]
12 | regex_t re;
| ^~
gcc "-LD:\\Cpp\\pcre\\lib" -o Test.exe Hello.o -lpcre -lpcreposix
19:57:21 Build Finished. 0 errors,1 warnings. (took 2s.400ms)
运行程序时,它返回0并按预期打印:
Hello,world!
有人可以帮助我了解幕后发生的事情并成功执行此regcomp函数吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)