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

最近的工作方向又发生了变化,暂时放下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在编译程序的时候需要添加调试信息。要不然你的需要调试的程序没有调试信息,那样你怎么搞都是白搞的。

《使用xcode去开发makefile的project(Building Makefile Projects With Xcode)》有36个想法

  1. 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

  2. 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??

  3. 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

  4. 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.

  5. 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.

  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. 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.

  8. 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

  9. 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

  10. 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

  11. Hello ,
    I’m Shea Rutledge.
    If you’ve ever been too busy and couldn’t finish a research assignment , then you’ve come to the right place. I work with students in all areas of the writing technique. I can also write the essay from start to finish.
    My career as a scholarly writer started early in college . After learning that I was very capable in the field of academic writing, I decided to take it up as a profession.

    Professional Academic Writer- Shea Rutledge- http://www.studioahz.comCorp

  12. Welcome Everyone
    Thanks for checking out my writing website . My name is Kobie Odling.
    I have worked since high school in this niche. My aptitude for writing started at a young age. I wrote journaled as a child and eventually went on to work with my school newspaper.
    This early tryst into reporting eventually led me to academic writing. There is plenty of work for qualified writers. I specialize in dissertations , but have the skills to do all types of academic writing.
    Email me for more information about rates and a price quote. I’m looking forward to helping you.

    Academic Writer – Kobie Odling – baileyanderson/writemyessay.todayCorps

  13. I’m an expert writer who loves to bring smiles to people’s face.

    Writing is what I do for a living and I am so passionate about this. I have worked with several associations whose goal is to help people solve problems.
    I love traveling and have visited several countries in the past few years.
    I’m happy to have written several books that have contributed positively to the lives of many. My books are available in several parts of the world. And I’m currently working with companies that help people save time. Being a part of this team has open more opportunities for me to excel as a writer. I have worked with different people and met many clients as a professional.
    I can handle any kind of writing and provide nothing but the best. People come to me all the time to ask if I can solve their writing problems and I accept. I find pleasure in assisting them to solve their problems as a professional.

    Academic Writer – Lowrie Aston – My Custom Essay Corps

  14. Hey, my name is Philip!

    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 can`t imagine my life without it.
    Most of my poems were sold throughout Canada, USA, Old England and even Russia. Also I`m working with services that help people to save their nerves.
    People ask me “Please, Philip, I need your professional help” and I always accept the request, `cause I know, that only I can save their time!

    Professional Academic Writer – Philip – Bronwyn LeighCorp

  15. My name is Keiren. And I am a professional Content writer with many years of experience in writing.

    My interest is to solve problems related to writing. And I have been doing it for many years. I have been with several organizations as a volunteer and have assisted people in many ways.
    My love for writing has no end. It is like the air we breathe, something I cherish with all my being. I am a passionate writer who started at an early age.
    I’m happy that I`ve already sold several copies of my poems in different countries like USA, Russia and others too numerous to mention.
    I also work in a company that provides assistance to many people from different parts of the world. Students always come to me because I work no matter how hard their projects are. I help them to save money, because I feel happy when people come to me for professional help.

    Academic Writer – Keiren – standrewspres.org Confederation

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注