Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example dynamic_simulation_full_y gives error while linking #219

Open
eshoubak opened this issue Sep 21, 2024 · 3 comments
Open

Example dynamic_simulation_full_y gives error while linking #219

eshoubak opened this issue Sep 21, 2024 · 3 comments

Comments

@eshoubak
Copy link

eshoubak commented Sep 21, 2024

I am installing my build in /usr/local/GridPACK

Then I copy the examples in /usr/local/GridPACK/share to my home folder.

From there I have no problem building the hello World example. I can also build the resistor grid fine.

However trying to build the dynamic full y simulation I get a ton of errors at the linking stage, too long to list here , but first few lines are:

==================================================
[ 0%] Built target dsf.x.input
[ 50%] Building CXX object CMakeFiles/dsf.x.dir/dsf_main.cpp.o
[100%] Linking CXX executable dsf.x
/usr/bin/ld: /usr/local/GridPACK/lib/libgridpack_powerflow_module.a(pf_app_module.cpp.o): in function gridpack::parser::PTI33_parser<gridpack::network::BaseNetwork<gridpack::powerflow::PFBus, gridpack::powerflow::PFBranch> >::getCase()': /root/develop/GridPACK/src/gridpack/parser/PTI33_parser.hpp:213: undefined reference to gridpack::parser::CaseParser33::CaseParser33(std::map<int, int, std::less, std::allocator<std::pair<int const, int> > >, std::map<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, int, std::less<std::__cxx11::basic_string<char, std::char_traits, std::allocator > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits, std::allocator > const, int> > >, std::map<std::pair<int, int>, int, std::less<std::pair<int, int> >, std::allocator<std::pair<std::pair<int, int> const, int> > >*)'
/usr/bin/ld: /root/develop/GridPACK/src/gridpack/parser/PTI33_parser.hpp:215: undefined reference to gridpack::parser::CaseParser33::parse(gridpack::stream::InputStream&, boost::shared_ptr<gridpack::component::DataCollection>&, double&, int&)' /usr/bin/ld: /root/develop/GridPACK/src/gridpack/parser/PTI33_parser.hpp:216: undefined reference to gridpack::parser::CaseParser33::~CaseParser33()'
...
...
...

All the linking error print out "~/develop/GridPACK/src/gridpack/parser/PTI33_parser.hpp" or a variation of it having to do with the parser. The weird thing is that the above directory is my build directory which I discarded after installation finished.

After I built GridPACK all CTests passed , and as I mentioned I can compile the first two examples.

However , the dynamic simulation is what I am most interested in. Hope someone can guide me to what is going on here !

Best Regards,
Ehab

@eshoubak eshoubak changed the title Example dynamic_simulation_full_y does gives error while linking Example dynamic_simulation_full_y gives error while linking Sep 21, 2024
@eshoubak
Copy link
Author

eshoubak commented Sep 21, 2024

I was able to compile it manually and run it now ! As follows:

`g++ -c dsf_main.cpp -I/usr/lib/x86_64-linux-gnu/openmpi/include
-I/usr/local/ga-5.8/include
-I/usr/local/GridPACK/include

g++ dsf_main.o
-L/usr/local/GridPACK/lib
-lgridpack_timer
-lgridpack_environment
-lgridpack_powerflow_module
-lgridpack_dynamic_simulation_full_y_module
-lgridpack_parallel
-lgridpack_partition
-lgridpack_pfmatrix_components
-lgridpack_ymatrix_components
-lgridpack_components
-lgridpack_stream
-lgridpack_block_parsers
-lgridpack_math
-lgridpack_configuration
-L/usr/local/ga-5.8/lib -lga++ -lga -larmci
-L/usr/local/boost-1.78.0/lib -lboost_mpi -lboost_serialization
-lboost_random
/usr/local/petsc-3.16.4/lib/libparmetis.so
/usr/local/petsc-3.16.4/lib/libpetsc.so.3.16
-L/usr/lib/x86_64-linux-gnu/openmpi/lib -lmpi_cxx -lmpi
-o dsf_main.x`

Tracking all the symbols down took some time, but it finally worked for me.

Something might be broken in CMakeLists.txt for this example. Keeping this open in case someone wants to fix the cmake process.

@JTZ83
Copy link

JTZ83 commented Sep 23, 2024

Will take a look

@eshoubak
Copy link
Author

eshoubak commented Sep 30, 2024

With Cmake the issue might be linking to some default Boost installation on the system rather than the 1.78.0 version the instructions specify. I kept having linking issues even with a whittled down CMakeLists :

cmake_minimum_required(VERSION 3.21)
project(DynamicSimulation)

enable_language(CXX)

add_executable(dsf.x
  dsf_main.cpp
  )

target_include_directories(dsf.x
  PRIVATE
  /usr/lib/x86_64-linux-gnu/openmpi/include
  /usr/local/ga-5.8/include
  /usr/local/GridPACK/include
  )

 
 # List of library names
 set(LIBRARIES_NAMES
   "mpi"
   "mpi_cxx"
   "petsc"
   "parmetis"
   "boost_random"
   "boost_serialization"
   "boost_mpi"
   "armci"
   "ga"
   "ga++"
   "gridpack_configuration"
   "gridpack_math"
   "gridpack_block_parsers"
   "gridpack_stream"
   "gridpack_components"
   "gridpack_ymatrix_components"
   "gridpack_pfmatrix_components"
   "gridpack_partition"
   "gridpack_parallel"
   "gridpack_dynamic_simulation_full_y_module"
   "gridpack_powerflow_module"
   "gridpack_environment"
   "gridpack_timer"
   )

# Variable to hold the paths of found libraries
set(LIBRARIES_FOUND)

# Step 1: Loop through the list to find each library
foreach(LIBRARY_NAME IN LISTS LIBRARIES_NAMES)

  find_library(LIBRARY_PATH NAMES ${LIBRARY_NAME}
    PATHS /usr/local/GridPACK/lib
    /usr/local/ga-5.8/lib
    /usr/local/petsc-3.16.4/lib
    /usr/local/boost-1.78.0/lib
    /usr/lib/x86_64-linux-gnu/openmpi/lib
    NO_CACHE
    NO_DEFAULT_PATH
    )

  # Check if the library was found
  if(NOT LIBRARY_PATH)
    message(FATAL_ERROR "Library '${LIBRARY_NAME}' could not be found.")
  endif()

  # Append the found library path to the LIBRARIES_FOUND list
  list(INSERT LIBRARIES_FOUND 0  ${LIBRARY_PATH})
  unset(LIBRARY_PATH)
endforeach()

message(STATUS "All Libraries found: ${LIBRARIES_FOUND}")


# Step 2: Link all found libraries to the executable
target_link_libraries(dsf.x PRIVATE ${LIBRARIES_FOUND} )

# Copy example files
add_custom_command(
    TARGET dsf.x POST_BUILD  # Run after the executable is built
    COMMAND ${CMAKE_COMMAND} -E copy
        "${CMAKE_SOURCE_DIR}/input_145.xml" "${CMAKE_BINARY_DIR}/input.xml"
    COMMENT "Copying xml configuration to the build directory"
    )

add_custom_command(
    TARGET dsf.x POST_BUILD  # Run after the executable is built
    COMMAND ${CMAKE_COMMAND} -E copy
        "${CMAKE_SOURCE_DIR}/IEEE_145bus_v23_PSLF.raw" "${CMAKE_BINARY_DIR}/IEEE_145bus_v23_PSLF.raw"
    COMMENT "Copying network file to the build directory"
    )

add_custom_command(
    TARGET dsf.x POST_BUILD  # Run after the executable is built
    COMMAND ${CMAKE_COMMAND} -E copy
         "${CMAKE_SOURCE_DIR}/IEEE_145b_classical_model.dyr" "${CMAKE_BINARY_DIR}/IEEE_145b_classical_model.dyr"
    COMMENT "Copying generator model to the build directory"
    )

find_library was always picking the wrong boost libraries until I discovered the "NO_DEFAULT_PATH" option which got it to link correctly.
Perhaps something similar is occurring the GridPACK Cmake files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants