Skip to content

Instantly share code, notes, and snippets.

@pitrou

pitrou/build.sh Secret

Last active May 11, 2022 13:31
Show Gist options
  • Save pitrou/1c892d1c42bd6ece9b68a9eb015b76c8 to your computer and use it in GitHub Desktop.
Save pitrou/1c892d1c42bd6ece9b68a9eb015b76c8 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -exuo pipefail
# CXXFLAGS=${CXXFLAGS//-fvisibility-inlines-hidden/}
${CXX} ${CXXFLAGS} ${LDFLAGS} -shared -DNDEBUG -o libtest.so lib.cpp
nm --demangle --defined-only libtest.so | grep Test
${CXX} ${CXXFLAGS} ${LDFLAGS} -L$(pwd) -g -DNDEBUG -o main-release main.cpp -ltest
LD_LIBRARY_PATH=$(pwd) ./main-release
${CXX} ${CXXFLAGS} ${LDFLAGS} -L$(pwd) -g -o main-debug main.cpp -ltest
LD_LIBRARY_PATH=$(pwd) ./main-debug
#include "lib.h"
Test::Test() {
this->ptr = new int(8);
}
#ifndef NDEBUG
Test::~Test() {
delete this->ptr;
}
#endif
void DoSomething() {
// Make sure the destructor is present inside the shared library.
static Test test{};
}
class Test {
public:
Test();
#ifdef NDEBUG
~Test() {
delete ptr;
}
#else
~Test();
#endif
int* ptr;
};
#include "lib.h"
int main () {
Test t = Test();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment