Compiler/Linker work around

This is a discussion on Compiler/Linker work around within the C Programming forums, part of the General Programming Boards category; Hi, I have 25 c modules.Out of these modules i generate prg file intended for two different devices.In the system ...

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    2

    Compiler/Linker work around

    Hi,
    I have 25 c modules.Out of these modules i generate prg file intended for two different devices.In the system these two devices work together.There is one module(Let's say module 10) with special function (let's say func_1()) in it which will be used by both device codes.Now when I compile these modules for first device it works fine as compiler knows function func_1().For second device Ican't compile module 10 as it's a requirement.Then I compile remaining 24 modules but I get error as it doesn't know func_1() which has been called from one of compiled modules.Well,this special function can not be moved somewhere else so my question is how do we work around with this situation????

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    > Ican't compile module 10 as it's a requirement.
    So where else were you planning to get func_1() from?

    In the other 24 modules, you either have:

    All calls to func_1() guarded by a conditional
    Code:
    #ifdef FOR_DEVICE_ONE
        func_1();
    #endif
    Or something to effectively remove the function
    Code:
    #ifdef FOR_DEVICE_TWO
    #define func_1()  /*empty*/
    #endif
    In either case, compiling for device 2 will not result in an unresolved symbol to func_1()
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    2
    Thank you very much Mr.salem.Let me illustrate whole situation.My application is Locomotive Engine control.I have two controller devices to conduct all the functionalities.One device acts as a master and other as a slave.Prototype of func_1() is accessible to both device code.There is one third party master module (lets's say master_drv.c) which defines func_1() and third party slave module(let's say slave_drv.c) which doesn't have func_1().Unfortunately func_1 is called by other global module e.g oil_system.c.When I compile code for master controller i do compile master_drv.c along with all other modules (including oil_system.c) and so all is well.But when I compile my code for slave i won't have defination for func_1() as i compille slave_drv.c(requirement) not master_drv.c which has actual defination for func_1().Also,I can't move func_1() into global module as it takes lots of dynamic variables which have been declared by master_drv.c only.I tried conditional compilation as you said but then linker will throw error for unresolved externals.I use microtech mcc68k compiler.Any ideas???.

  4. #4
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Ewe, yuck. Perhaps you should define a structure with function pointers in your new code that reference the old code (or vice versa) so that you can "register" your new functions in the old code and perhaps even break out the old functions in the new code. -- This is often done in the Linux kernel so that code can be reused without junking up the name space too badly.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    Or even some newlines in sentences

    Do the symbols in slave_drv.c and master_drv.c overlap, apart from this func_1?

    Making a library out of just master_drv.o, then adding that library to the end of your slave compilation may solve the problem.

    If the linker/librarian is smart, it might just pull out the compiled version of func_1 for you.

    But the better long term answer is to start refactoring your code a bit.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21