首页 > IT, 编程 > 使用xcode去开发makefile的project(Building Makefile Projects With Xcode)

使用xcode去开发makefile的project(Building Makefile Projects With Xcode)

2014年2月19日 发表评论 阅读评论

最近的工作方向又发生了变化,暂时放下IOS的开发。不过业余时间还是会继续研究IOS和MAC的原生程序开发的。这次又走回以前的伤疤–视频。希望这次可以成功。以前在视频这块搞左好多年。但是产品没有出来,最终已失败告终。这次一定要把产品搞出来。要不然以后都不再接触视频这一块。

言归正传,由于需要搞视频这一块,又需要重回到C/C++的大家庭。又需要解决开发环境的问题。经过多放面的考察和选择,暂定选择了xcode为开发环境,这2-3年都是使用xcode作为开发环境。一是熟悉。而且xcode有插件配置成VI的编辑模式。而且在mac属于POSIX系统。mac与linux的跨平台运行应该问题不大。可以在mac上进行测试与调试。最后再在linux测试。应该不会有太大的问题。不需要在开发的时候老是开着虚拟机。

使用xcode会存在一个问题,如何与编译现有的开源软件或者将来编写的程序进行跨平台编译。不过xcode还是比较强大的。支持makefile编译。具体如何做,请看官方说明。说明比较清晰。不过我还是来一篇图文说明,并把我遇到的问题给大家说明一下。省得大家走弯路。使用的是xcode 5。并使用一个流媒体的的开源软件Live555作为说明(live555这个软件下载解压后需要运行./genMakefiles macosx生成makefile)。

1、新建项目,选择Command Line Tool。(其实选择其他都可以,不过千万别选择External build system ,因为如果选择了这个,将会失去智能提示与定义跳转)。

Screen Shot 2014-02-18 at 5.24.04 PM

Screen Shot 2014-02-19 at 11.21.37 AM

按Next,然后选择目录,我选择在原有的软件Live555目录下,xcode会自动live555目录下创建一个与项目名称相同的目录。千万别别与原来的软件在同一目录下并和原有软件相同的名字,要不然xcode会把原来的目录内容删除。

Screen Shot 2014-02-18 at 5.26.03 PM

添加项目的所有文件到xcode 项目中。请记得选择(Create groups for any added folders),要不然加入项目后的文件。不能做智能提示和跳转定义。做不了这些功能的还要IDE干嘛,直接用sublime就好了。是否选择使用Copy items into destination group’s folder(if needed),这个根据你项目存放路径和需要。根据我的项目存放在Live555下,我是不需要选择的。

Screen Shot 2014-02-18 at 5.27.17 PM

在项目中点击“Add Target…”(根据上图)

Screen Shot 2014-02-18 at 5.27.35 PM

选择“External Build System” ,然后如下填写内容。

Screen Shot 2014-02-19 at 11.41.10 AM

点击Finish。后,需要在Live555这个target的setting做设置,主要是Directory这个目录。需要填写你项目的makefile所在的路径。如果你的makefile与你的xcode project文件同一路径是不需要更改。由于我的makefile在project文件的上一层目录,所以使用了”../”。也可以使用绝对路径,不过还是建议使用相对路径比较好。

Screen Shot 2014-02-18 at 5.31.03 PM 这时候就设置好了,可以选择tager Live555进行编译运行。

Screen Shot 2014-02-18 at 5.29.22 PM

应该一切顺利。编译成功。而且查看代码,可以有定义跳转,编辑的时候有智能语法提示。非常好,满足要求。

不过后来发现一个问题,就是编译的时候,发现有错误,不能点击错误,定位到错误在什么文件与那一行。经过一番上网搜索,还是没有找到答案。

Screen Shot 2014-02-18 at 5.42.58 PM

唯有自己研究,仔细查看了编译的输出,明明有错误文件名,和错误位置的输出。但是xcode就是不会定位错误的地方。后来发现错误输出只有文件名字,没有对应的目录。感觉应该是路径的问题。我编译的时候是在最上层的makefile,而makefile是通过cd命令进入各个目录中,再进行make的命令操作。所以xcode不知道是那个目录下有该文件,只会在根makefile所在的目录下进行寻找。为了验证这样的想法。新添加多一个target–mediaServer,mediaServer的Makefile Directory指向../mediaServer/。

Screen Shot 2014-02-19 at 1.45.00 PM

通过编译mediaServer这个target。就可以点击错误,直接定位到错误的地方。这样终于大功告成了。

Screen Shot 2014-02-18 at 5.43.27 PM

虽然这样做有点麻烦,不过应该够用了。因为对于大型的开源软件来说,改动的机会不多,主要是阅读为主。就是要修改,修改量也不多。这样应该够用了。对于自己开发的项目,只要写makefile的时候注意下就可以避免了这种情况了。

至于单步执行与调试,我没有试。因为我不太喜欢单步调试,比较习惯打印日志这种方式比较多。估计有同样的问题。

PS:补充单步调试,虽然不喜欢,但是在阅读别人的代码的时候需要搞清楚别人的思路还是需要单步调试的,特别是C++,类的重载,好多时候阅读代码比较困难,不清楚究竟调用子类的函数,还是父类的函数。需要单步调试的时候设置断点,参考函数调用堆栈,来了解清楚程序的运行。

xcode单步调试makefile的项目。在stack overflow找到这个答案了。

方法好简单:

1、菜单Product—>Scheme–>Edit scheme  然后选择makefile的schemem。

2、然后在Run的的info页面的Executable选择Other,然后选择需要调试运行的程序位置。

3、Options页面的Working directory 选择use custom working  directory ,选择与执行文件相同的路径就可以了。

另外需要注意的是makefile在编译程序的时候需要添加调试信息。要不然你的需要调试的程序没有调试信息,那样你怎么搞都是白搞的。

分类: IT, 编程 标签: , , , ,
  1. 2019年12月6日16:00 | #1

    Hello everyone, it’s Liam here!
    I work as an academic writer and have created this content with the intent of changing your life for the better. I started honing my writing abilities in my school years. I learned that my fellow students needed writing help—and they were willing to pay for it. The money was enough to help pay my tuition for my first semester of college.
    Ever since school, I have continued to work as an academic writer. I was hired by a writing service based in the United Kingdom. Since then, the research papers that I have created have been sold around Europe and the United States.
    In my line of work, I have become accustomed to hearing, “Liam Scott, can you help me meet my writing assignment deadline?” I know that I can save their time.

    Academic Writer – Liam – Natalie Crawford Band

  2. 2019年11月18日16:59 | #2

    Hello everyone , I’m Simona.
    Welcome to my about page. I started writing in high school after a creative writing assignment for my English teacher. I did creative writing for several months before I thought about doing something else.
    I had always loved doing research assignments because I’m passionate about learning. When you combine writing talent with a love of learning, research paper writing only makes sense as a job.
    I’m passionate about aiding the students of the future in their school career. When they don’t like their assignment , I am there to help.

    Simona Ortega – Writing Expert – Transatlanticstudies Company

  3. 2019年10月28日17:33 | #3

    Hi guys, my name is Ahelly House!

    I`m an academic writer and I`m going to change your lifes onсe and for all
    Writing has been my passion for a long time and now I cannot imagine my life without it.
    Most of my works were sold throughout Canada, USA, Old England and even Australia. Also I`m working with services that help people to save their nerves.
    People ask me “Please, Ahelly House, I need your professional help” and I always accept the request, `cause I know, that only I can save their time!

    Professional Academic Writer – Ahelly – https://www.homeownereducationnetwork.com/ – Homeownereducationnetwork Company

  4. 2017年9月7日01:52 | #4

    early favorite si colombia sa mga youtube at okey din exposure nia. ang prediction nga sa mga youtube si colombia ang mananalo at tama nga.

  5. 2017年9月7日01:52 | #5

    Completely and absolutely ACCURATE for ME. Now I know why I have such a FASCINATION with butterflies.

  6. 2017年9月7日01:51 | #6

    Hi all of u guys i would like to say be patient about the drug as i posted dat i was vomiting every morning since i started the combination drug its almost 3weeks nw m feeling well its my third month taking it hop it will treat u well too as time goes on.

  7. 2017年9月7日01:51 | #7

    My CD4 count is 154 and i am not taking the treatment. How dangerous is to not be taking treatment yet?

  8. 2017年9月7日01:50 | #8

    Hi all of u guys i would like to say be patient about the drug as i posted dat i was vomiting every morning since i started the combination drug its almost 3weeks nw m feeling well its my third month taking it hop it will treat u well too as time goes on.

  9. 2017年9月7日01:50 | #9

    I love an all blue outfit and the top and shoes are such perfect pieces – great way to dress up jeans!

  10. 2017年9月7日01:50 | #10

    Hi! I am writing to you because I’m also a daydreamer and a dreamer, and we are alike, but most importantly because my guide is a white owl. I came this page because I thought mine would be a wolf so I had to read what it was about. I too had recurring nightmares of a lone wolf from ages 6 to 12-ish. It scared me then badly. But today it is my favorite animal. So majestic, powerful, and disciplined. I’m not necessarily a man of God(not against either), but I send my good energy and clarity to you from an Owl to a Wolf… because if you are going to fill some shoes, you might as well make them big ones.

  11. 2017年9月7日01:49 | #11

    I was very pleased to uncover this site.

  12. 2017年9月7日01:49 | #12

    I am genuinely grateful to the owner of this site who has shared this fantastic paragraph at here.

  13. 2017年9月7日01:49 | #13

    Hi. I hear people always complaining about Tribuss and side effects. When I started treatment the side effects only last a for few days not even a week. I’m starting to worry if it could be that the drugs are resistant? Or is no longer working? I haven’t gone again yet for the second check ups and the CD4 etc. Thanks for your concern

  14. 2017年9月7日01:48 | #14

    a buttefly flew into my house today and landed on my arm then slowly flew around me, despite the cold wet weather & i didnt think they survived this long it was beautiful in colour & seemed so calm, does this mean anything??

  15. 2017年9月7日01:48 | #15

    Доброго времени! Пока таких планов нет, но не исключена такая возможность.

  16. 2017年9月7日01:48 | #16

    Love the fern pic. Makes me feel there. Funny how you escaped the fog and I keep on priayng for it here. I’m dying to take some misty pics. Welcome back JJ, good to have ya!

  17. 2017年9月7日01:47 | #17

    Feeling kasi ng ibang pinoy lahi sila ng magaganda at pinagyayabang pa sa ibang lahi. Kaya hindi nkakapagtaka kapag may bisitang banyaga at madissappoint sa makikita. Lolz

  18. 2017年9月7日01:47 | #18

    Pero pag nagartista yan dito tulad ni Puerto Rico Dayanara Torres madaming Pinoy magiging fans niyan hahaha. Babaw nating mga Pinoy.

  19. 2017年9月7日01:47 | #19

    Love the way you mixed the print! And your tan, love it!

  20. 2017年2月22日09:12 | #20
  1. 2015年9月20日04:02 | #1
  2. 2016年10月23日09:30 | #2