diff --git a/src/tools/gcc.lua b/src/tools/gcc.lua index 79f6758a..9713c2e0 100644 --- a/src/tools/gcc.lua +++ b/src/tools/gcc.lua @@ -174,27 +174,25 @@ function premake.gcc.getlinkflags(cfg) local result = { } ---[[ - for _, value in ipairs(premake.getlinks(cfg, "dependencies", "object")) do - -- don't use "-llib" arguments when linking static libraries + + for _, value in ipairs(premake.getlinks(cfg, "siblings", "object")) do if (value.kind == "StaticLib") then + -- don't use "-lname" when linking static libraries + -- instead use path/Name.ext so as not to link with a SharedLib of the same name + -- if one is present. local pathstyle = premake.getpathstyle(value) local namestyle = premake.getnamestyle(value) local linktarget = premake.gettarget(value, "link", pathstyle, namestyle, cfg.system) table.insert(result, linktarget.fullpath) - print(pathstyle .. " " .. namestyle .. " " ..linktarget.fullpath) else - if path.getextension(value.basename) == ".framework" then - table.insert(result, '-framework ' .. _MAKE.esc(path.getbasename(value.basename))) - else - table.insert(result, '-l' .. _MAKE.esc(value.basename)) - end + --premake does not support creating frameworks so this is just a SharedLib link + --link using -lname + table.insert(result, '-l' .. _MAKE.esc(value.linktarget.basename)) end end ---]] + -- "-llib" is fine for system dependencies - --for _, value in ipairs(premake.getlinks(cfg, "system", "basename")) do - for _, value in ipairs(premake.getlinks(cfg, "all", "basename")) do + for _, value in ipairs(premake.getlinks(cfg, "system", "basename")) do if path.getextension(value) == ".framework" then table.insert(result, '-framework ' .. _MAKE.esc(path.getbasename(value))) else diff --git a/tests/actions/make/test_make_linking.lua b/tests/actions/make/test_make_linking.lua index 74acab24..5404bc12 100644 --- a/tests/actions/make/test_make_linking.lua +++ b/tests/actions/make/test_make_linking.lua @@ -30,49 +30,67 @@ sln = nil end - local get_buffer = function() + local get_buffer = function(projectName) io.capture() premake.buildconfigs() - local cfg = premake.getconfig(linksToStaticProj, 'Debug', 'Native') + local cfg = premake.getconfig(projectName, 'Debug', 'Native') premake.gmake_cpp_config(cfg, premake.gcc) local buffer = io.endcapture() return buffer end - function suite.ProjectLinksToStaticPremakeMadeLibrary_linksUsingTheFormat_pathNameExtension() - local buffer = get_buffer() + + function suite.projectLinksToStaticPremakeMadeLibrary_linksUsingTheFormat_pathNameExtension() + local buffer = get_buffer(linksToStaticProj) local format_exspected = 'LIBS %+%= bar/libstaticPrj.a' test.string_contains(buffer,format_exspected) end - T.absolute_path_error= { } - local firstSharedLib = nil - local linksToFirstSharedLib = nil - function T.absolute_path_error.setup() + T.link_suite= { } + local firstProject = nil + local linksToFirstProject = nil + + function T.link_suite.setup() _ACTION = "gmake" solution('dontCareSolution') - configurations{'Debug'} - platforms {} + configurations{'Debug'} + end + + function T.link_suite.tear_down() + _ACTION = nil + firstProject = nil + linksToFirstProject = nil + end + + function T.link_suite.projectLinksToSharedPremakeMadeLibrary_linksUsingFormat_dashLName() + + firstProject = project 'firstProject' + kind 'SharedLib' + language 'C' + + linksToFirstProject = project 'linksToFirstProject' + kind 'ConsoleApp' + language 'C' + links{'firstProject'} - firstSharedLib = project 'firstSharedLib' - configuration{'Debug'} - kind 'SharedLib' + local buffer = get_buffer(linksToFirstProject) + local format_exspected = 'LIBS %+%= %-lfirstProject' + test.string_contains(buffer,format_exspected) + end + + function T.link_suite.projectLinksToPremakeMadeConsoleApp_doesNotLinkToConsoleApp() + + firstProject = project 'firstProject' + kind 'ConsoleApp' language 'C' - --files{'first.c'} - linksToFirstSharedLib = project 'linksToFirstSharedLib' - configuration{'Debug'} - kind 'SharedLib' + linksToFirstProject = project 'linksToFirstProject' + kind 'ConsoleApp' language 'C' - links{'firstSharedLib'} + links{'firstProject'} + + local buffer = get_buffer(linksToFirstProject) + local format_exspected = 'LIBS %+%=%s+\n' + test.string_contains(buffer,format_exspected) end - function T.absolute_path_error.tear_down() - firstSharedLib = nil - linksToFirstSharedLib = nil - end - function T.absolute_path_error.setUp_doesNotAssert() - premake.buildconfigs() - local cfg = premake.getconfig(linksToFirstSharedLib, 'Debug', 'Native') - premake.gmake_cpp_config(cfg, premake.gcc) - end