From af9d1f8f15a57a99af376bd6b30730ff9b9812b1 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 20 Apr 2017 14:40:19 -0700 Subject: [PATCH] Add a testcase for linking C and C++ static archives into a shared library This exercises a regression where the C rather than C++ linker is chosen, resulting in symbol errors. Test for #1653 --- test cases/common/146 C and CPP link/foo.c | 19 +++++++++++++ test cases/common/146 C and CPP link/foo.cpp | 24 ++++++++++++++++ test cases/common/146 C and CPP link/foo.h | 16 +++++++++++ test cases/common/146 C and CPP link/foo.hpp | 24 ++++++++++++++++ test cases/common/146 C and CPP link/foobar.c | 23 +++++++++++++++ test cases/common/146 C and CPP link/foobar.h | 16 +++++++++++ .../common/146 C and CPP link/meson.build | 28 +++++++++++++++++++ 7 files changed, 150 insertions(+) create mode 100644 test cases/common/146 C and CPP link/foo.c create mode 100644 test cases/common/146 C and CPP link/foo.cpp create mode 100644 test cases/common/146 C and CPP link/foo.h create mode 100644 test cases/common/146 C and CPP link/foo.hpp create mode 100644 test cases/common/146 C and CPP link/foobar.c create mode 100644 test cases/common/146 C and CPP link/foobar.h create mode 100644 test cases/common/146 C and CPP link/meson.build diff --git a/test cases/common/146 C and CPP link/foo.c b/test cases/common/146 C and CPP link/foo.c new file mode 100644 index 000000000..77c7e39ff --- /dev/null +++ b/test cases/common/146 C and CPP link/foo.c @@ -0,0 +1,19 @@ +/* Copyright © 2017 Dylan Baker + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "foo.h" + +int forty_two(void) { + return 42; +} diff --git a/test cases/common/146 C and CPP link/foo.cpp b/test cases/common/146 C and CPP link/foo.cpp new file mode 100644 index 000000000..639af8e32 --- /dev/null +++ b/test cases/common/146 C and CPP link/foo.cpp @@ -0,0 +1,24 @@ +/* Copyright © 2017 Dylan Baker + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include + +namespace { + std::vector numbers = boost::assign::list_of(61); +} + +extern "C" int six_one(void) { + return numbers[1]; +} diff --git a/test cases/common/146 C and CPP link/foo.h b/test cases/common/146 C and CPP link/foo.h new file mode 100644 index 000000000..1ed8ce9b3 --- /dev/null +++ b/test cases/common/146 C and CPP link/foo.h @@ -0,0 +1,16 @@ +/* Copyright © 2017 Dylan Baker + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +int forty_two(void); diff --git a/test cases/common/146 C and CPP link/foo.hpp b/test cases/common/146 C and CPP link/foo.hpp new file mode 100644 index 000000000..e47f01dce --- /dev/null +++ b/test cases/common/146 C and CPP link/foo.hpp @@ -0,0 +1,24 @@ +/* Copyright © 2017 Dylan Baker + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +int six_one(void); + +#ifdef __cplusplus +} +#endif diff --git a/test cases/common/146 C and CPP link/foobar.c b/test cases/common/146 C and CPP link/foobar.c new file mode 100644 index 000000000..bd6cb00a4 --- /dev/null +++ b/test cases/common/146 C and CPP link/foobar.c @@ -0,0 +1,23 @@ +/* Copyright © 2017 Dylan Baker + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "foo.h" +#include "foo.hpp" +#include "foobar.h" + +void mynumbers(int nums[]) { + nums[0] = forty_two(); + nums[1] = six_one(); +} diff --git a/test cases/common/146 C and CPP link/foobar.h b/test cases/common/146 C and CPP link/foobar.h new file mode 100644 index 000000000..6dcb09664 --- /dev/null +++ b/test cases/common/146 C and CPP link/foobar.h @@ -0,0 +1,16 @@ +/* Copyright © 2017 Dylan Baker + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +void mynumbers(int nums[]); diff --git a/test cases/common/146 C and CPP link/meson.build b/test cases/common/146 C and CPP link/meson.build new file mode 100644 index 000000000..bfee4b2c7 --- /dev/null +++ b/test cases/common/146 C and CPP link/meson.build @@ -0,0 +1,28 @@ +# Copyright © 2017 Dylan Baker +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +project('C and C++ static link test', ['c', 'cpp'], + default_options : ['cpp_std=c++03']) + +dep_boost = dependency('boost') + +libcppfoo = static_library('cppfoo', ['foo.cpp', 'foo.hpp'], + dependencies : dep_boost) +libcfoo = static_library('cfoo', ['foo.c', 'foo.h']) + +libfoo = shared_library( + 'foo', + ['foobar.c', 'foobar.h'], + link_with : [libcfoo, libcppfoo], +)