From b507996d9251690a29bc7b603b7c8834ab130cba Mon Sep 17 00:00:00 2001 From: David Hendriks <davidhendriks93@gmail.com> Date: Thu, 20 Feb 2020 18:13:06 +0000 Subject: [PATCH] added fPIC to custom logging compiler. should solve issue on desktop pc. also fixed bug of precode requirement --- README.md | 2 ++ binarycpython/utils/custom_logging_functions.py | 4 +++- binarycpython/utils/grid.py | 13 +++++++------ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7d1ac7d8f..ccb681b36 100644 --- a/README.md +++ b/README.md @@ -50,3 +50,5 @@ When running a jupyter notebook and importing binary_c, it might happen that the Also: I figured that having binaryc output the log like "<LOG HEADER> t=10e4 ..." (i.e. printing the parameter names as well as their values) would be useful because in that way one can easily have python read that out automatically instead of having to manually copy the list of parameter names. See examples/ dir for some working examples + +When you try to `import binary_c_python_api` and python complains about it not existing, but you are sure that you correctly included the necessary pythonpaths, then you probably need to rebuild the package: \ No newline at end of file diff --git a/binarycpython/utils/custom_logging_functions.py b/binarycpython/utils/custom_logging_functions.py index a583292fd..12af7c84b 100644 --- a/binarycpython/utils/custom_logging_functions.py +++ b/binarycpython/utils/custom_logging_functions.py @@ -240,6 +240,8 @@ def return_compilation_dict(verbose=0): def compile_shared_lib(code, sourcefile_name, outfile_name, verbose=0): """ Function to write the custom logging code to a file and then compile it. + + TODO: nicely put in the -fPIC """ # Write code to file @@ -257,7 +259,7 @@ def compile_shared_lib(code, sourcefile_name, outfile_name, verbose=0): compilation_dict = return_compilation_dict(verbose) # Construct full command - command = "{cc} {ccflags} {libs} -o {outfile_name} {sourcefile_name} {inc}".format( + command = "{cc} -fPIC {ccflags} {libs} -o {outfile_name} {sourcefile_name} {inc}".format( cc=compilation_dict["cc"], ccflags=compilation_dict["ccflags"], libs=compilation_dict["libs"], diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py index ee822191c..2207af134 100644 --- a/binarycpython/utils/grid.py +++ b/binarycpython/utils/grid.py @@ -1108,13 +1108,14 @@ class Population(object): ######################### # Setting up pre-code and value in some cases # Add pre-code - code_string += ( - indent * (depth + 1) - + "{}".format( - grid_variable["precode"].replace("\n", "\n" + indent * (depth + 1)) + if grid_variable["precode"]: + code_string += ( + indent * (depth + 1) + + "{}".format( + grid_variable["precode"].replace("\n", "\n" + indent * (depth + 1)) + ) + + "\n" ) - + "\n" - ) # Set phasevol code_string += indent * (depth + 1) + "phasevol *= phasevol_{}\n".format( -- GitLab