Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7716127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:33:32+00:00 2026-06-01T02:33:32+00:00

How to build a .bundle from source code? This might sound like a simple

  • 0

How to build a .bundle from source code?

This might sound like a simple problem but it has been hurdling me for a week…

Here is my problem:

I have a bunch of .c and .h files that are organized in a folder and its sub folders. The source code was written and compiled with gcc make and tested by many other make tools. The source code has some utilities and command line tools and it has more code that serve as library for those utilities and tools. It is the files that serve as libraries that I want to reuse. (By library I don’t mean static library or something, I just mean that some .c and .h files in certain subfolders provide functions that can be called by some other .c files. I want to be able to call those functions, too)

Yet my problem is more complex than that: I need to build those .c and .h into a bundle to reuse it. I am not writing my application in C; I am developing in Unity and Unity can only take in .bundle files on Mac OS.

Here is my goal:

Organize the source code folder in a proper way so that I can build them into a bundle in Xcode 4.

Here is where I got stuck:

When building the project I got the following error:

Duplicate symbol _main in
/Users/zeningqu/Library/Developer/Xcode/DerivedData/ccn-cfygrtkrshubpofnfxalwimtyniq/Build/Intermediates/ccn.build/Debug/ccn.build/Objects-normal/i386/ccndsmoketest.o
and
/Users/zeningqu/Library/Developer/Xcode/DerivedData/ccn-cfygrtkrshubpofnfxalwimtyniq/Build/Intermediates/ccn.build/Debug/ccn.build/Objects-normal/i386/ccnd_main.o
for architecture i386

I can relate to this error because I can find lots of main entries in the source code. Most of them are test utilities.

Here is what I tried:

  1. I tried removing all those utility .c files but with no luck. The error is still there. I delete and delete until some files cannot find the definition of the function they are calling. So I had to stop there.

  2. Though I wasn’t able to build a bundle I was able to build a C/C++ static library (with an .a extension). After I got the .a file I tried to put it into another Xcode project and tried to build it into a bundle. I could build a bundle in that way, but then I had problem accessing the content of the bundle. How do I call functions defined in a .a static library if that library is hidden in a bundle? I read about Apple’s documentation which says:

Note: Some Xcode targets (such as shell tools and static libraries) do
not result in the creation of a bundle or package. This is normal and
there is no need to create bundles specifically for these target
types. The resulting binaries generated for those targets are intended
to be used as is.

(quoted from: https://developer.apple.com/library/mac/#documentation/CoreFoundation/Conceptual/CFBundles/AboutBundles/AboutBundles.html#//apple_ref/doc/uid/10000123i-CH100-SW1)

Here is what I thought about:

  1. I thought about replacing all main with something like main_sth. But the source code was not written by me so I didn’t want to modify it. (It just doesn’t feel like a proper way of doing things to me…)
  2. I learnt that Xcode has gcc compiler built in. So I guess if gcc can make it, so can Xcode? It’s just a wild guess – I am not familiar with Xcode and gcc.

Here is a summary of my questions:

  1. Is there a way to properly organize a pile of code previously compiled and made by gcc make so that they can be built into an Xcode bundle?
  2. Is it meaningful to put a .a library in an Xcode project and build it into a bundle? If it is meaningful, how do I call functions defined in .a after it is built into a bundle?
  3. Is it proper to just replace all main() entries with something else?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:33:33+00:00Added an answer on June 1, 2026 at 2:33 am

    Alright I think I have figured out at least one solution to the problem.

    The duplicate main error was caused by a bunch of main entries in my source code. When the code was compiled by gcc make, I guess the author defined a sort of compilation order so that duplicate mains won’t be an issue. (If you know how to do this, please let me know. I barely know make tools.) But when I just add the entire source code folder into my Xcode project, of course Xcode would complain during linking…

    As I was unwilling to modify the source code (because the source code library is not developed by me), I decided to use another strategy to walk around this problem.

    If your duplicate main error was reported from your own code, you can stop reading here. But if you are like me, with a bunch of gcc compiled source code and badly need a bundle yet don’t know what to do, I may be able to help.

    Okay here is what I did:

    1. I set up an empty workspace.

    2. I built a C/C++ static library project.

    3. Import my entire source code folder into the static library project.

    4. Set some header search path for the static library project.

    5. Build the static library project. (Now I have a .a library which I could link against)

    6. I set up another project, with a bundle target.

    7. At the bundle project -> Build Phases -> Link Binary with Libraries, add the .a library that I just built.

    8. At the bundle project -> edit scheme -> Build, add the static library project to the scheme and move it up the list so that it is built prior to my bundle project.

    9. Then add .h files of my library project to my bundle project as references.

    10. After that, add a .c file in my bundle project that basically functions as a wrapper. I picked a function that I want to call in Unity, wrote a wrapper function in the new .c file, and was able to build the bundle.

    11. After several trial and error, I was able to import the bundle into Unity and was able to call the test function from Unity.

    I was really excited about this! Though it’s not completed yet I think this gives me hope and I am confident I can use the source code now! And the best thing about this solution is that I don’t have to modify the library code developed by others. Whenever they update their code, I just update my .a library and that’s it!

    Though I have listed 11 steps I still feel that there are lots of details that I missed. So here are my references:

    1. I followed this tutorial to build my source code into a static library: http://www.ccnx.org/?post_type=incsub_wiki&p=1315

    2. I followed this blog to link static library against my bundle code and twist build phases and search headers: http://blog.carbonfive.com/2011/04/04/using-open-source-static-libraries-in-xcode-4/

    3. I followed this doc to import my bundle to Unity3D Pro as a plugin: http://unity3d.com/support/documentation/Manual/Plugins.html

    I strongly recommend the second reference because that’s what solved my problem!

    Though the problem is almost solved there are still a few things that I haven’t figured out:

    1. I don’t know if a wrapper function is at all necessary. I will try this out tomorrow and come back to update.

    — I am coming back to update: the wrapper function is NOT necessary. Just make sure you have all the headers in your bundle project and you will be able to use all the data structures and call functions defined in your headers.

    1. I haven’t used NSBundle class though I read a few docs about it. Previously I was thinking about using that class to access my .a library encapsulated in my bundle, but as I found the solution I wrote above, I didn’t try the class out.

    Lastly, if you have better solution, please don’t hesitate to let me know!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to to build a Felix bundle in Eclipse. This basically includes
I installed Ruby 1.9.2 from source and was using it for a while but
This page has info about Bundles with mkbundle , but when I tried to
Hey Guys I'm trying to get the Railscasts source code from github. when I'm
The build.xml has a test and a build target. The test target obviously depends
OK, I've been using sqlite3 as development successfully for this tiny rails 3.1 project,
Has anyone actually managed to accomplish this? I tried the approach suggested here ,
I'm trying to create an ePub file in android. Below is my source code.
Initial Problem I was using yaml_db in a Rails project, but it seems the
Many years ago I build a simple system for handling languageversioning of texts in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.