OK, Here is a reproducible example. I have identified the issue as lying in how I have structured my CMakeLists. Previously, I was compiling my project files as a dylib and then linking to the executable main fn. I was doing this because I also have a python API for my program (passing various graph attributes and simulation parameters from python, running simulation in C++, then returning the results to python). Linking the main executable to the compiled library produced the strange behavior, where deleting edges did not also delete the corresponding attributes. If I change the CMakeLists.txt to directly link the project files to the executable, things behave as expected. However, then I’m not sure why the library is compiling strangely.
I am developing currently on MacOSX 12.4. Our server cluster, that previously was limiting me from upgrading past igraph 0.9.10, runs Ubuntu 18. I have added a local install of CMake on the cluster to match the version on my mac. Everything in both environments is now running CMake 3.20 and igraph 10.4. This issue persisted on both Mac and Ubuntu after upgrading Cmake and igraph.
src/main.cpp:
#include<igraph.h>
#include<iostream>
#include "BICS_ABM.h"
using namespace std;
#define MAXCHAR 1000
int main(int argc, char **argv) {
igraph_t graph;
igraph_set_attribute_table(&igraph_cattribute_table);
igraph_full(&graph, 100, false, false);
test_routine(&graph);
cout << "Ran routine" << endl;
DELALL(&graph);
igraph_destroy(&graph);
return 0;
}
src/BICS_ABM.cpp (This normally contains the main routine run in the program):
#include<igraph.h>
#include<vector>
#include<string>
#include<iostream>
#include "BICS_ABM.h"
void test_routine(igraph_t* graph) {
igraph_vector_t temp_v;
igraph_vector_init(&temp_v, igraph_ecount(graph));
SETEANV(graph, "type", &temp_v);
SETEANV(graph, "duration", &temp_v);
igraph_vector_int_t edges_to_delete;
igraph_vector_int_init(&edges_to_delete, 10);
for (int i = 0; i < 10; i++) {
VECTOR(edges_to_delete)[i] = i * 10;
}
igraph_delete_edges(graph, igraph_ess_vector(&edges_to_delete));
igraph_vector_int_destroy(&edges_to_delete);
/* Pull edge attribute vector */
igraph_vector_resize(&temp_v, 0);
EANV(graph, "type", &temp_v);
cout << "Number of edges in graph: " << igraph_ecount(graph) << "; Number of items in attribute vector: " << igraph_vector_size(&temp_v) << endl;
igraph_vector_destroy(&temp_v);
}
src/BICS_ABM.h:
#include <igraph.h>
using namespace std;
void test_routine(igraph_t* graph) ;
Ran the following shell commands to add igraph library:
% git submodule add https://github.com/igraph/igraph.git
% cd igraph
% git checkout 0.10.4
Previously, I had the following CMakelists.txt file. This yielded the incorrect behavior by printing
Number of edges in graph: 4940; Number of items in attribute vector: 4950
cmake_minimum_required(VERSION 3.16)
set (CMAKE_CXX_STANDARD 17)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
project(BICS_ABM)
add_subdirectory(igraph)
add_library(BICS_ABM_lib SHARED
src/BICS_ABM.h
src/BICS_ABM.cpp
)
add_executable(BICS_ABM
src/main.cpp
)
target_link_libraries(BICS_ABM_lib PUBLIC igraph)
target_link_libraries(BICS_ABM PUBLIC BICS_ABM_lib igraph)
Using the following CMakeLists.txt we get the correct result:
Number of edges in graph: 4940; Number of items in attribute vector: 4940
cmake_minimum_required(VERSION 3.16)
set (CMAKE_CXX_STANDARD 17)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
project(BICS_ABM)
add_subdirectory(igraph)
add_library(BICS_ABM_lib SHARED
src/BICS_ABM.h
src/BICS_ABM.cpp
)
add_executable(BICS_ABM
src/BICS_ABM.h
src/BICS_ABM.cpp
src/main.cpp
)
target_link_libraries(BICS_ABM_lib PUBLIC igraph)
target_link_libraries(BICS_ABM PUBLIC igraph)