免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1915 | 回复: 1
打印 上一主题 下一主题

[C] linux下编译问题 库的使用 急!!!! [复制链接]

论坛徽章:
1
巨蟹座
日期:2013-12-03 13:34:29
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-02-25 13:27 |只看该作者 |倒序浏览
比如我开发一个gtk的程序 编译时候这么gcc -o app app.c `pkg-config --libs --cflags gtk+-2.0`
现在我要使用rpm库开发一个rpm相关的程序(rpm库已经安装), 那么在pkg-config 里面应该怎么用 `pkg-config --libs --cflags rpm-4.0` 这个不行   

附源码:
  1. #include <errno.h>
  2. #include <fcntl.h>
  3. #include <stdio.h>
  4. #include <unistd.h>
  5. #include <string.h>

  6. #include <rpm/rpmlib.h>

  7. int main()
  8. {

  9. ts = rpmtsCreate();

  10. rpmtsSetRootDir(ts, NULL);
  11. add_for_install(ts, optarg, upgrade);
  12. tsi = rpmtsiInit(ts);
  13. rc = rpmtsCheck(ts);
  14. probs = rpmtsProblems(ts);
  15. if (rc || probs->numProblems > 0) {
  16. rpmpsPrint(fp, probs); // trying to redirect install logs to a file
  17. while(fgets(buf,128,fp))
  18. {
  19. data.append(buf);
  20. }
  21.   
  22. rpmpsFree(probs);
  23. rpmtsFree(ts);
  24. exit(rc);
  25. }


  26. /* Create ordering for the transaction */

  27. rc = rpmtsOrder(ts);
  28. if (rc > 0) {
  29. printf("Ordering failed\n");
  30. rpmtsFree(ts);
  31. exit(rc);
  32. }
  33. rpmtsClean(ts);


  34. /* Set callback routine & flags, for example -vh */


  35. notifyFlags |= INSTALL_LABEL | INSTALL_HASH;
  36. rpmtsSetNotifyCallback(ts, rpmShowProgress, (void *)notifyFlags);


  37. /* Set transaction flags and run the actual transaction */


  38. rpmtsSetFlags(ts, (rpmtransFlags)(rpmtsFlags(ts) | tsFlags));
  39. rc = rpmtsRun(ts, NULL, (rpmprobFilterFlags)probFilter);


  40. /* Check for results .. */


  41. if (rc || probs->numProblems > 0)
  42. rpmpsPrint(fp, probs);
  43. while(fgets(buf,128,fp))
  44. {
  45. data.append(buf); // trying to redirect logs to a file
  46. }
  47. rpmpsFree(probs);
  48. rpmtsFree(ts);
  49. exit(rc);

  50. }


  51.   

  52. int add_for_install(rpmts ts, char *file, int upgrade)
  53. {
  54. FD_t fd;
  55. Header hdr;
  56. int rc = 0;
  57. rpmRelocation * relocs;
  58. relocs = (rpmRelocation *)malloc(2*sizeof(rpmRelocation));
  59. relocs->oldPath = "/opt/";
  60. relocs->newPath = "/mnt/tmp"; // trying to relocate installation to a diff directory
  61. fd = Fopen(file, "r.ufdio");
  62. if (fd == NULL) {
  63. printf("Unable to open file %s\n", file);
  64. return 1;
  65. }
  66.   
  67. rc = rpmReadPackageFile(ts, fd, file, &hdr);
  68. if (rc != RPMRC_OK) {
  69. printf("Unable to read package %s\n", file);
  70. return rc;
  71. }

  72. /* Add it to the transaction set */

  73. rc = rpmtsAddInstallElement(ts, hdr, file, upgrade,relocs);
  74.   
  75. if (rc) {
  76. printf("Error adding %s to transaction\n", file);
  77. goto out;
  78. }
  79. out:
  80. headerFree(hdr);
  81. Fclose(fd);
  82. return rc;
  83. }
复制代码

论坛徽章:
0
2 [报告]
发表于 2011-02-25 17:22 |只看该作者
比如我开发一个gtk的程序 编译时候这么gcc -o app app.c `pkg-config --libs --cflags gtk+-2.0`
现在我要 ...
wshn13 发表于 2011-02-25 13:27



     把错误贴出来! 代码暂时不重要!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP