Are there general guidelines for solving undefined reference/unresolved symbol issues?

后端 未结 2 451
走了就别回头了
走了就别回头了 2021-01-12 10:36

I\'m having several \"undefined reference\" (during linkage) and \"unresolved symbol\" (during runtime after dlopen) issues where I work. It is quite a large makefile system

2条回答
  •  借酒劲吻你
    2021-01-12 11:09

    Setting up a build system where X depends on Y which depends on Z helps. It's when you get into circles (Z depends on X) that things get ugly.

    Oftentimes it's the order libraries are linked ("-lZ -lY -lX" vs "-lX -lY -lZ") that causes grief. More rarely, you have the same library-name in multiple places on your search path, or your linking against outdated versions that have not yet been recompiled.

    "nm --demangle" can let you see where things are defined/used.

    "ldd" can be used to see what dynamic libraries you depend on.

    The gcc/g++ flag -print-file-name=LIBRARY can help track down exactly which library is being used.


    Afterthought: (Since you ask about rules/guidelines.)

    It is possible to set up a makefile system such that:

    • If module=D depends on modules A,B,&C.
    • Then trying to make module=D would first make modules A,B,&C.
    • And, more importantly, module=D would automatically determine its libraries (-lA,etc), library paths (-LA), and include paths (-IA) from the makefiles for modules A,B,&C.

    That can get a little hairy to set up. Last time I did it, I favored merely caching the information rather than forking an excessive number of make subprocesses. Coupled with makefile-importing and a little perl script to remove duplicates. Kludgey, I know. (Powers that be didn't want to spend time on infrastructure.) But it can be done.

    Then again, I was using GNU-make, which has a few extensions.

提交回复
热议问题