Skip to content

Commit e6f05c1

Browse files
committed
Add project wholearchive
1 parent 35830f2 commit e6f05c1

File tree

8 files changed

+110
-0
lines changed

8 files changed

+110
-0
lines changed

projects/wholearchive/Readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## wholearchive:
2+
3+
Export static library content from another shared library

projects/wholearchive/premake5.lua

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
if (_ACTION == nil) then
2+
return
3+
end
4+
5+
local LocationDir = "solution/%{_ACTION}"
6+
7+
workspace "Project"
8+
location(LocationDir)
9+
configurations {"Debug", "Release"}
10+
11+
objdir(path.join(LocationDir, "obj")) -- premake adds $(configName)/$(AppName)
12+
targetdir(path.join(LocationDir, "bin/%{cfg.buildcfg}"))
13+
14+
startproject "app"
15+
16+
project "app"
17+
kind "ConsoleApp"
18+
targetname "app"
19+
20+
files { "src/main.cpp" }
21+
22+
defines { 'USING_DLL', 'USING_DLL_LIB' }
23+
links 'dll'
24+
25+
project "dll"
26+
kind "SharedLib"
27+
targetname "dll"
28+
29+
files { "src/dll.cpp", 'src/dll.h' }
30+
31+
defines { 'MAKING_DLL', 'MAKING_DLL_LIB' }
32+
filter { 'toolset:msc*' }
33+
dependson 'lib'
34+
linkoptions { '/WHOLEARCHIVE:bin/%{cfg.buildcfg}/lib.lib' }
35+
filter { 'toolset:gcc', 'system:windows' }
36+
dependson 'lib'
37+
linkoptions { '-Wl,--whole-archive bin/%{cfg.buildcfg}/lib.lib -Wl,--no-whole-archive' }
38+
filter { 'toolset:gcc', 'system:not windows' }
39+
dependson 'lib'
40+
linkoptions { '-Wl,--whole-archive bin/%{cfg.buildcfg}/liblib.a -Wl,--no-whole-archive' }
41+
filter {}
42+
--links 'lib'
43+
44+
project "lib"
45+
kind "StaticLib"
46+
targetname "lib"
47+
48+
defines { 'MAKING_DLL_LIB' }
49+
files { "src/lib.cpp", 'src/lib.h' }
50+
51+
project "test"
52+
kind "ConsoleApp"
53+
targetname "test"
54+
55+
files { "src/test.cpp" }
56+
links 'lib'

projects/wholearchive/src/dll.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "dll.h"
2+
3+
void foo() {}

projects/wholearchive/src/dll.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "lib.h"
2+
3+
#ifdef _MSC_VER
4+
# ifdef MAKING_DLL
5+
# define IMPORT_EXPORT __declspec(dllexport)
6+
# elif defined(USING_DLL)
7+
# define IMPORT_EXPORT __declspec(dllimport)
8+
# else // not making nor using DLL
9+
# define IMPORT_EXPORT
10+
# endif
11+
#else
12+
# define IMPORT_EXPORT
13+
#endif
14+
15+
IMPORT_EXPORT void foo();

projects/wholearchive/src/lib.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "lib.h"
2+
3+
void bar()
4+
{
5+
}

projects/wholearchive/src/lib.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
#ifdef _MSC_VER
4+
# ifdef MAKING_DLL_LIB
5+
# define IMPORT_EXPORT_LIB __declspec(dllexport)
6+
# elif defined(USING_DLL_LIB)
7+
# define IMPORT_EXPORT_LIB __declspec(dllimport)
8+
# else // not making nor using DLL
9+
# define IMPORT_EXPORT_LIB
10+
# endif
11+
#else
12+
# define IMPORT_EXPORT_LIB
13+
#endif
14+
15+
IMPORT_EXPORT_LIB void bar();

projects/wholearchive/src/main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "dll.h"
2+
3+
int main()
4+
{
5+
bar();
6+
foo();
7+
}

projects/wholearchive/src/test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "lib.h"
2+
3+
int main()
4+
{
5+
bar();
6+
}

0 commit comments

Comments
 (0)