~tomleb/meson_version_script

c04bbf064857e7a0098c4c63eb77f2800dff4e26 — Tom Lebreux 1 year, 9 months ago
Initial commit
9 files changed, 119 insertions(+), 0 deletions(-)

A .gitignore
A examples/main.c
A examples/meson.build
A foo.syms
A include/bar.h
A include/foo.h
A meson.build
A src/bar.c
A src/foo.c
A  => .gitignore +1 -0
@@ 1,1 @@
build/

A  => examples/main.c +11 -0
@@ 1,11 @@
#include "foo.h"

extern int bar_1(char *, int);
// extern int bar_2(char *, int); <- undefined reference

int main(int argc, char *argv[]) {
	foo_1("calling foo_1");
	foo_2("calling foo_2");
	bar_1("calling bar_1", 2);
	// bar_2("calling bar_2", 2); <- undefined reference
}

A  => examples/meson.build +5 -0
@@ 1,5 @@
executable(
	'main',
	'main.c',
	dependencies: [foo_dep],
)

A  => foo.syms +7 -0
@@ 1,7 @@
FOO_0_0 {
  global:
    foo*;
    bar_1;
  local:
    bar*;
};

A  => include/bar.h +7 -0
@@ 1,7 @@
#ifndef BAR_H
#define BAR_H

int bar_1(char *, int);
int bar_2(char *, int);

#endif /* BAR_H */

A  => include/foo.h +7 -0
@@ 1,7 @@
#ifndef FOO_H
#define FOO_H

int foo_1(char *);
int foo_2(char *);

#endif /* FOO_H */

A  => meson.build +50 -0
@@ 1,50 @@
project(
	'foo',
	'c',
	default_options: [
		'c_std=c11',
		'warning_level=2',
		'werror=true',
	],
)

cc = meson.get_compiler('c')

add_project_arguments(cc.get_supported_arguments([
	'-Wundef',
	'-Wlogical-op',
	'-Wmissing-include-dirs',
	'-Wold-style-definition',
	'-Wpointer-arith',
	'-Winit-self',
	'-Wstrict-prototypes',
	'-Wimplicit-fallthrough=2',
	'-Wendif-labels',
	'-Wstrict-aliasing=2',
	'-Woverflow',

	'-Wno-missing-braces',
	'-Wno-missing-field-initializers',
	'-Wno-unused-parameter',
]), language: 'c')


symbols_file = 'foo.syms'
symbols_flag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), symbols_file)

foo_lib = shared_library(
	'foo',
	files(
		'src/bar.c',
		'src/foo.c',
	),
	include_directories: ['include'],
  link_args : symbols_flag,
)

foo_dep = declare_dependency(
	link_with: foo_lib,
	include_directories: ['include'],
)

subdir('examples')

A  => src/bar.c +21 -0
@@ 1,21 @@
#include <stdio.h>

#include "bar.h"

static void static_bar(char *string) {
	printf("%s\n", string);
}

int bar_1(char *string, int count) {
	for (int i = 0; i < count; i++) {
		static_bar(string);
	}
	return 0;
}

__attribute__((visibility ("hidden"))) int bar_2(char *string, int count) {
	for (int i = 0; i < count; i++) {
		static_bar(string);
	}
	return 0;
}

A  => src/foo.c +10 -0
@@ 1,10 @@
#include "bar.h"
#include "foo.h"

int foo_1(char *string) {
	return bar_1(string, 10);
}

int foo_2(char *string) {
	return bar_2(string, 10);
}