Last active
August 4, 2022 13:39
-
-
Save gglin001/7daabeb1512ad8f4e40f293f90ff28bd to your computer and use it in GitHub Desktop.
ubuntu gcc from apt issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.0) | |
project(project) | |
set(CMAKE_VERBOSE_MAKEFILE ON) | |
# a shared library | |
add_library(lib SHARED lib.cpp) | |
add_executable(main main.cpp) | |
# link with lib | |
target_link_libraries(main PRIVATE lib) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
static void func() { std::cout << "\n\n\n\nfuncfucnfucn\n\n\n\n"; } | |
// run before main expectedly ! | |
static int dummy = (func(), 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
int main(int argc, char *argv[]) { | |
std::cout << "main" << std::endl; | |
return 0; | |
} |
without cmake
/usr/bin/g++ lib.cpp --shared -fPIC -o liblib.so
/usr/bin/g++ main.cpp -l lib -o main
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if you compile this project using gcc/g++ from
apt install gcc g++
, thefunc()
inlib.cpp
will not run expectedly> ./build/main main
but with manually compiled gcc or gcc from conda, yoiu will get evertything work
> ./build/main funcfucnfucn main