premake / premake/premake-core

codelite circular reference problem when using static libraries

Open
#517 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug codelite help wanted
Dominant language
C
Stars
3.6k
Forks
654
Avg merge
1d 1h
Merged PRs (30d)
13

Description

Hi, I'm new to using premake5 and codelite, but have encountered an issue that took most of the day to figure out. When a StaticLib project includes a different StaticLib project defined elsewhere and is linked to a ConsoleApp project through project linking cyclic references are not resolved correctly because codelite adds the project reference as a link option. This is added to the end of link command, after all the other libraries (where it should have been in front). Here is an example:

workspace "MyWorkspace"
    project "Project1"
        kind "StaticLib"
        libdirs { "/path/to/externalLib" }
        links { "externalLib" }

    project "Project2"
        kind "ConsoleApp"
        libdirs { "/path/to/externalLib" }
        links { "Project1",
                "externalLib" }
        files { "example.cpp" }

In Project2 even though externalLib is included after Project1, Project1 has unresolved symbols. Here is an example linker command:

/usr/lib/gcc/x86_64-linux-gnu/4.9/collect2 [.. skipping plugin opts, other opts & lib dirs ..] /obj/example.cpp.o -lexternalLib /bin/libProject1.a [.. skipping system libs ..]

This does not affect gmake Makefile because it's library output is enclosed in --start-group and --end-group and Project1 is at the start of libs like so:

/usr/lib/gcc/x86_64-linux-gnu/4.9/collect2 [.. skipping plugin opts, other opts & lib dirs ..] /obj/example.cpp.o --start-group /bin/libProject1.a -lexternalLib --end-group [.. skipping system libs ..]

I don't know if this is a gotcha, or a bug with premake/codelite, but am reporting it here in case someone else comes across the same issue. In my opinion the solution would be for codelite to move all object file definitions before libraries. As it stands I have changed the Project1 name and am linking into Project2 from the product directory:

workspace "MyWorkspace"
    --note the underscore in the name
    project "Project_1"
        targetname "Project1"
        kind "StaticLib"
        libdirs { "/path/to/externalLib" }
        links { "externalLib" }

    project "Project2"
        kind "ConsoleApp"
        --note the path to the Project1 product dir
        libdirs { "/path/to/externalLib",
                  "/path/to/Project_1/bin" }
        links { "Project1",
                "externalLib" }
        files { "example.cpp" }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the MyWorkspace example with Project1, Project2, externalLib, and the generated Codelite project; no source file or test entry point is named. Compare the Codelite link command with the gmake command, and consider the work done when circular static-library references link correctly without the project-renaming workaround.

Written by the indexing model from the issue text.

Assessment

Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.