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

'ld: symbol(s) not found for architecture x86_64' Problem with compiling the intro_to_forpy.F90 example on MacOS #44

Open
sankalpjena opened this issue Jun 14, 2022 · 6 comments

Comments

@sankalpjena
Copy link

I'm using the following gfortran:
GNU Fortran (Homebrew GCC 11.3.0_1) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

My python version is 3.9.12 and package manager is conda.

Upon compiling the program with: gfortran intro_to_forpy.F90 forpy_mod.o -fno-lto python3-config --ldflags
I get the following error:

$ gfortran intro_to_forpy.F90 forpy_mod.o -fno-lto `python3-config --ldflags`
Undefined symbols for architecture x86_64:
  "_PyBool_FromLong", referenced from:
      ___forpy_mod_MOD_forpy_initialize_bool in forpy_mod.o
  "_PyBuffer_FillContiguousStrides", referenced from:
      ___forpy_mod_MOD_ndarray_create_nocopy_helper in forpy_mod.o
  "_PyBuffer_IsContiguous", referenced from:
      ___forpy_mod_MOD_get_data_helper in forpy_mod.o
  "_PyBuffer_Release", referenced from:
      ___forpy_mod_MOD_get_data_helper in forpy_mod.o
  "_PyBytes_AsString", referenced from:
      ___forpy_mod_MOD_unbox_value_char_1d in forpy_mod.o
  "_PyBytes_FromStringAndSize", referenced from:
      ___forpy_mod_MOD_box_value_char_1d_as_bytestr in forpy_mod.o
      ___forpy_mod_MOD_box_value_chars_as_bytestr in forpy_mod.o
  "_PyComplex_AsCComplex", referenced from:
      ___forpy_mod_MOD_unbox_value_complex_real64 in forpy_mod.o
      ___forpy_mod_MOD_unbox_value_complex_real32 in forpy_mod.o
  "_PyComplex_FromDoubles", referenced from:
      ___forpy_mod_MOD_box_value_complex_real64 in forpy_mod.o
      ___forpy_mod_MOD_box_value_complex_real32 in forpy_mod.o
      ___forpy_mod_MOD_forpy_initialize_complex in forpy_mod.o
  "_PyDict_Clear", referenced from:
      ___forpy_mod_MOD_dict_clear in forpy_mod.o
  "_PyDict_Copy", referenced from:
      ___forpy_mod_MOD_dict_copy in forpy_mod.o
  "_PyDict_GetItemString", referenced from:
      ___forpy_mod_MOD_print_py in forpy_mod.o
      ___forpy_mod_MOD_forpy_initialize_exceptions in forpy_mod.o
  "_PyDict_Items", referenced from:
      ___forpy_mod_MOD_dict_items in forpy_mod.o
  "_PyDict_Keys", referenced from:
      ___forpy_mod_MOD_dict_keys in forpy_mod.o
  "_PyDict_New", referenced from:
      ___forpy_mod_MOD_dict_create in forpy_mod.o
  "_PyDict_Values", referenced from:
      ___forpy_mod_MOD_dict_values in forpy_mod.o
  "_PyErr_Clear", referenced from:
      ___forpy_mod_MOD_err_clear in forpy_mod.o
      ___forpy_mod_MOD_is_ndarray in forpy_mod.o
      ___forpy_mod_MOD_forpy_initialize_exceptions in forpy_mod.o
  "_PyErr_GivenExceptionMatches", referenced from:
      ___forpy_mod_MOD_exception_matches in forpy_mod.o
  "_PyErr_Occurred", referenced from:
      ___forpy_mod_MOD_have_exception in forpy_mod.o
      ___forpy_mod_MOD_err_print in forpy_mod.o
      ___forpy_mod_MOD_exception_matches in forpy_mod.o
      ___forpy_mod_MOD_unbox_value_complex_real64 in forpy_mod.o
      ___forpy_mod_MOD_unbox_value_complex_real32 in forpy_mod.o
      ___forpy_mod_MOD_unbox_value_real64 in forpy_mod.o
      ___forpy_mod_MOD_unbox_value_real32 in forpy_mod.o
      ...
  "_PyErr_Print", referenced from:
      ___forpy_mod_MOD_err_print in forpy_mod.o
  "_PyErr_SetString", referenced from:
      ___forpy_mod_MOD_raise_exception in forpy_mod.o
  "_PyEval_GetBuiltins", referenced from:
      ___forpy_mod_MOD_print_py in forpy_mod.o
      ___forpy_mod_MOD_forpy_initialize_exceptions in forpy_mod.o
  "_PyFloat_AsDouble", referenced from:
      ___forpy_mod_MOD_unbox_value_real64 in forpy_mod.o
      ___forpy_mod_MOD_unbox_value_real32 in forpy_mod.o
  "_PyFloat_FromDouble", referenced from:
      ___forpy_mod_MOD_box_value_real64 in forpy_mod.o
      ___forpy_mod_MOD_box_value_real32 in forpy_mod.o
      ___forpy_mod_MOD_forpy_initialize_float in forpy_mod.o
  "_PyImport_ImportModule", referenced from:
      ___forpy_mod_MOD_import_py in forpy_mod.o
      ___forpy_mod_MOD_forpy_initialize_numpy in forpy_mod.o
  "_PyList_Append", referenced from:
      ___forpy_mod_MOD_list_append_chars in forpy_mod.o
      ___forpy_mod_MOD_list_append_char_1d in forpy_mod.o
      ___forpy_mod_MOD_list_append_logical in forpy_mod.o
      ___forpy_mod_MOD_list_append_complex_real64 in forpy_mod.o
      ___forpy_mod_MOD_list_append_complex_real32 in forpy_mod.o
      ___forpy_mod_MOD_list_append_real64 in forpy_mod.o
      ___forpy_mod_MOD_list_append_real32 in forpy_mod.o
      ...
  "_PyList_Insert", referenced from:
      ___forpy_mod_MOD_list_insert_int64 in forpy_mod.o
      ___forpy_mod_MOD_list_insert_int32 in forpy_mod.o
  "_PyList_New", referenced from:
      ___forpy_mod_MOD_list_create_empty in forpy_mod.o
  "_PyList_Reverse", referenced from:
      ___forpy_mod_MOD_list_reverse in forpy_mod.o
  "_PyList_Sort", referenced from:
      ___forpy_mod_MOD_list_sort in forpy_mod.o
  "_PyLong_AsLongLongAndOverflow", referenced from:
      ___forpy_mod_MOD_unbox_value_int64 in forpy_mod.o
      ___forpy_mod_MOD_unbox_value_int32 in forpy_mod.o
  "_PyLong_FromLongLong", referenced from:
      ___forpy_mod_MOD_box_value_int64_as_long in forpy_mod.o
      ___forpy_mod_MOD_box_value_int32_as_long in forpy_mod.o
  "_PyMapping_HasKey", referenced from:
      ___forpy_mod_MOD_mapping_contains in forpy_mod.o
  "_PyMemoryView_FromBuffer", referenced from:
      ___forpy_mod_MOD_ndarray_create_nocopy_helper in forpy_mod.o
  "_PyModule_AddObject", referenced from:
      ___forpy_mod_MOD_pythonmodule_add_object in forpy_mod.o
  "_PyModule_Create2", referenced from:
      ___forpy_mod_MOD_pythonmodule_init in forpy_mod.o
  "_PyObject_Call", referenced from:
      ___forpy_mod_MOD_ndarray_create_nocopy_helper in forpy_mod.o
      ___forpy_mod_MOD_call_py_object in forpy_mod.o
  "_PyObject_DelItem", referenced from:
      ___forpy_mod_MOD_mapping_delitem_chars in forpy_mod.o
      ___forpy_mod_MOD_mapping_delitem_int64 in forpy_mod.o
      ___forpy_mod_MOD_mapping_delitem_int32 in forpy_mod.o
      ___forpy_mod_MOD_mapping_delitem_object in forpy_mod.o
  "_PyObject_GetAttr", referenced from:
      ___forpy_mod_MOD_object_getattribute in forpy_mod.o
      ___forpy_mod_MOD_forpy_initialize_numpy in forpy_mod.o
  "_PyObject_GetBuffer", referenced from:
      ___forpy_mod_MOD_get_data_helper in forpy_mod.o
  "_PyObject_GetItem", referenced from:
      ___forpy_mod_MOD_dict_get_helper2 in forpy_mod.o
      ___forpy_mod_MOD_dict_get_helper in forpy_mod.o
      ___forpy_mod_MOD_mapping_getitem_chars_chars in forpy_mod.o
      ___forpy_mod_MOD_mapping_getitem_chars_char_1d in forpy_mod.o
      ___forpy_mod_MOD_mapping_getitem_chars_logical in forpy_mod.o
      ___forpy_mod_MOD_mapping_getitem_chars_complex_real64 in forpy_mod.o
      ___forpy_mod_MOD_mapping_getitem_chars_complex_real32 in forpy_mod.o
      ...
  "_PyObject_IsInstance", referenced from:
      ___forpy_mod_MOD_is_ndarray in forpy_mod.o
  "_PyObject_IsTrue", referenced from:
      ___forpy_mod_MOD_unbox_value_logical in forpy_mod.o
  "_PyObject_Length", referenced from:
      ___forpy_mod_MOD_unbox_value_char_1d in forpy_mod.o
      ___forpy_mod_MOD_mapping_len_int64 in forpy_mod.o
      ___forpy_mod_MOD_mapping_len_int32 in forpy_mod.o
      ___forpy_mod_MOD_sequence_len_int64 in forpy_mod.o
      ___forpy_mod_MOD_sequence_len_int32 in forpy_mod.o
  "_PyObject_SetAttr", referenced from:
      ___forpy_mod_MOD_object_delattr in forpy_mod.o
      ___forpy_mod_MOD_object_setattr in forpy_mod.o
  "_PyObject_SetItem", referenced from:
      ___forpy_mod_MOD_dict_get_helper in forpy_mod.o
      ___forpy_mod_MOD_mapping_setitem_chars_chars in forpy_mod.o
      ___forpy_mod_MOD_mapping_setitem_chars_char_1d in forpy_mod.o
      ___forpy_mod_MOD_mapping_setitem_chars_logical in forpy_mod.o
      ___forpy_mod_MOD_mapping_setitem_chars_complex_real64 in forpy_mod.o
      ___forpy_mod_MOD_mapping_setitem_chars_complex_real32 in forpy_mod.o
      ___forpy_mod_MOD_mapping_setitem_chars_real64 in forpy_mod.o
      ...
  "_PyObject_Str", referenced from:
      ___forpy_mod_MOD_cast_nonstrict_to_chars in forpy_mod.o
      ___forpy_mod_MOD_str_create_object in forpy_mod.o
  "_PyRun_SimpleString", referenced from:
      ___forpy_mod_MOD_run_string in forpy_mod.o
      ___forpy_mod_MOD_forpy_initialize_sys_argv in forpy_mod.o
  "_PySequence_Concat", referenced from:
      ___forpy_mod_MOD_tuple_add in forpy_mod.o
      ___forpy_mod_MOD_list_add in forpy_mod.o
  "_PySequence_Contains", referenced from:
      ___forpy_mod_MOD_sequence_contains in forpy_mod.o
  "_PySequence_Count", referenced from:
      ___forpy_mod_MOD_sequence_count_int64 in forpy_mod.o
      ___forpy_mod_MOD_sequence_count_int32 in forpy_mod.o
  "_PySequence_DelItem", referenced from:
      ___forpy_mod_MOD_list_delitem_int64 in forpy_mod.o
      ___forpy_mod_MOD_list_delitem_int32 in forpy_mod.o
  "_PySequence_GetItem", referenced from:
      ___forpy_mod_MOD_sequence_getitem_int64_chars in forpy_mod.o
      ___forpy_mod_MOD_sequence_getitem_int64_char_1d in forpy_mod.o
      ___forpy_mod_MOD_sequence_getitem_int64_logical in forpy_mod.o
      ___forpy_mod_MOD_sequence_getitem_int64_complex_real64 in forpy_mod.o
      ___forpy_mod_MOD_sequence_getitem_int64_complex_real32 in forpy_mod.o
      ___forpy_mod_MOD_sequence_getitem_int64_real64 in forpy_mod.o
      ___forpy_mod_MOD_sequence_getitem_int64_real32 in forpy_mod.o
      ...
  "_PySequence_Index", referenced from:
      ___forpy_mod_MOD_sequence_index_int64 in forpy_mod.o
      ___forpy_mod_MOD_sequence_index_int32 in forpy_mod.o
  "_PySequence_List", referenced from:
      ___forpy_mod_MOD_list_create_object in forpy_mod.o
  "_PySequence_SetItem", referenced from:
      ___forpy_mod_MOD_mutablesequence_setitem_int64_chars in forpy_mod.o
      ___forpy_mod_MOD_mutablesequence_setitem_int64_char_1d in forpy_mod.o
      ___forpy_mod_MOD_mutablesequence_setitem_int64_logical in forpy_mod.o
      ___forpy_mod_MOD_mutablesequence_setitem_int64_complex_real64 in forpy_mod.o
      ___forpy_mod_MOD_mutablesequence_setitem_int64_complex_real32 in forpy_mod.o
      ___forpy_mod_MOD_mutablesequence_setitem_int64_real64 in forpy_mod.o
      ___forpy_mod_MOD_mutablesequence_setitem_int64_real32 in forpy_mod.o
      ...
  "_PySequence_Tuple", referenced from:
      ___forpy_mod_MOD_tuple_create_object in forpy_mod.o
  "_PySys_GetObject", referenced from:
      ___forpy_mod_MOD_get_sys_path in forpy_mod.o
  "_PyTuple_New", referenced from:
      ___forpy_mod_MOD_ndarray_create_nocopy_helper in forpy_mod.o
      ___forpy_mod_MOD_tuple_create_int64 in forpy_mod.o
      ___forpy_mod_MOD_tuple_create_int32 in forpy_mod.o
  "_PyTuple_SetItem", referenced from:
      ___forpy_mod_MOD_ndarray_create_nocopy_helper in forpy_mod.o
      ___forpy_mod_MOD_tuple_setitem_int64_object in forpy_mod.o
      ___forpy_mod_MOD_tuple_setitem_int32_object in forpy_mod.o
      ___forpy_mod_MOD_tuple_setitem_int64_chars in forpy_mod.o
      ___forpy_mod_MOD_tuple_setitem_int64_char_1d in forpy_mod.o
      ___forpy_mod_MOD_tuple_setitem_int64_logical in forpy_mod.o
      ___forpy_mod_MOD_tuple_setitem_int64_complex_real64 in forpy_mod.o
      ...
  "_PyType_IsSubtype", referenced from:
      ___forpy_mod_MOD_is_unicode in forpy_mod.o
      ___forpy_mod_MOD_is_bool in forpy_mod.o
      ___forpy_mod_MOD_is_complex in forpy_mod.o
      ___forpy_mod_MOD_is_float in forpy_mod.o
  "_PyUnicode_AsUTF8AndSize", referenced from:
      ___forpy_mod_MOD_unbox_value_char_1d in forpy_mod.o
  "_PyUnicode_DecodeUTF8", referenced from:
      ___forpy_mod_MOD_box_value_char_1d_as_unicodestr in forpy_mod.o
      ___forpy_mod_MOD_box_value_chars_as_unicodestr in forpy_mod.o
      ___forpy_mod_MOD_forpy_initialize_unicode in forpy_mod.o
  "_Py_DecRef", referenced from:
      ___forpy_mod_MOD_cast_nonstrict_to_chars in forpy_mod.o
      ___forpy_mod_MOD_ndarray_create_nocopy_helper in forpy_mod.o
      ___forpy_mod_MOD_dict_get_chars_chars in forpy_mod.o
      ___forpy_mod_MOD_dict_get_chars_char_1d in forpy_mod.o
      ___forpy_mod_MOD_dict_get_chars_logical in forpy_mod.o
      ___forpy_mod_MOD_dict_get_chars_complex_real64 in forpy_mod.o
      ___forpy_mod_MOD_dict_get_chars_complex_real32 in forpy_mod.o
      ...
  "_Py_Finalize", referenced from:
      ___forpy_mod_MOD_forpy_finalize in forpy_mod.o
  "_Py_IncRef", referenced from:
      ___forpy_mod_MOD_unsafe_cast_from_c_ptr in forpy_mod.o
      ___forpy_mod_MOD_pythonmodule_add_object in forpy_mod.o
      ___forpy_mod_MOD_assign_py_nonetype in forpy_mod.o
      ___forpy_mod_MOD_assign_py_module_py in forpy_mod.o
      ___forpy_mod_MOD_assign_py_type_py in forpy_mod.o
      ___forpy_mod_MOD_assign_py_ndarray in forpy_mod.o
      ___forpy_mod_MOD_assign_py_dict in forpy_mod.o
      ...
  "_Py_Initialize", referenced from:
      ___forpy_mod_MOD_forpy_initialize in forpy_mod.o
  "_Py_IsInitialized", referenced from:
      ___forpy_mod_MOD_forpy_initialize in forpy_mod.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

Could you please help?

Thanking you

Best regards
Sankalp Jena

@sankalpjena sankalpjena changed the title Problem with compiling the intro_to_forpy.F90 example on MacOS ld: symbol(s) not found for architecture x86_64 Problem with compiling the intro_to_forpy.F90 example on MacOS Jun 15, 2022
@sankalpjena sankalpjena changed the title ld: symbol(s) not found for architecture x86_64 Problem with compiling the intro_to_forpy.F90 example on MacOS 'ld: symbol(s) not found for architecture x86_64' Problem with compiling the intro_to_forpy.F90 example on MacOS Jun 15, 2022
@ylikx
Copy link
Owner

ylikx commented Jun 16, 2022

Ok, that means that it could not link with libpython. Try python3-config --ldflags --embed. The embed option was added in newer versions of Python and is probably necessary for successfully linking.

@sankalpjena
Copy link
Author

Ok, that means that it could not link with libpython. Try python3-config --ldflags --embed. The embed option was added in newer versions of Python and is probably necessary for successfully linking.

I tried this and I'm getting the error that library wasn't found:

% gfortran intro_to_forpy.F90 forpy_mod.o -fno-lto `python3-config --ldflags --embed`
ld: library not found for -lpython3.9
collect2: error: ld returned 1 exit status

I tried export LD_LIBRARY_PATH=/usr/local/Caskroom/miniconda/base/envs/data_sc_env/lib:$LD_LIBRARY_PATH as well, but it didn't work

@ylikx
Copy link
Owner

ylikx commented Jun 17, 2022

Did you activate the conda environment with conda activate?
What is the output of python3-config --ldflags --embed on your system?

@sankalpjena
Copy link
Author

python3-config --ldflags --embed

Yes, I have activated my conda environment:

(data_sc_env) sankalp@jenambp collisionV1 % gfortran intro_to_forpy.F90 forpy_mod.o -fno-lto `python3-config --ldflags --embed`
ld: library not found for -lpython3.9
collect2: error: ld returned 1 exit status

The output:

(data_sc_env) sankalp@jenambp collisionV1 % python3-config --ldflags --embed
-L/usr/local/Caskroom/miniconda/base/envs/data_sc_env/lib/python3.9/config-3.9-darwin -lpython3.9 -ldl -framework CoreFoundation

@ylikx
Copy link
Owner

ylikx commented Jun 19, 2022

Apparently there is no shared library libpython3.9 in the directory specified by the python3-config output (/usr/local/Caskroom/miniconda/base/envs/data_sc_env/lib/python3.9/config-3.9-darwin). Check if there is a shared library named something like libpython3.9.dylib. If not, maybe you can find it in some other directory and adjust the path accordingly.

I do not have a macOS machine available, therefore I cannot test the setup with macOS + anaconda myself. It could also be that Python is built without shared library support.

@wakeupthemonkey
Copy link

I get this error: The 'sklearn' PyPI package is deprecated, use 'scikit-learn'

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

3 participants