add openssl in ns-3.36

405 views
Skip to first unread message

Shelly R

unread,
Sep 4, 2022, 2:25:45 PM9/4/22
to ns-3-users
how to lcrypto and lssl flags in CMakeCache.txt file to use openssl in ns-3.36.1. Give any suggestion about it

Gabriel Ferreira

unread,
Sep 4, 2022, 2:51:45 PM9/4/22
to ns-3-users
If you are using CMake 3.12, you can use 


Then add ${OPENSSL_LIBRARIES} to the LIBRARIES_TO_LINK argument of your target.

e.g.

find_package(OpenSSL)
if(${OPENSSL_FOUND}) # Test if ssl and crypto were found
    build_lib(
        LIBNAME custom_library
        SOURCE_FILES model/custom_library.cc
        HEADER_FILES model/custom_library.h
        LIBRARIES_TO_LINK ${libcore} ${OPENSSL_LIBRARIES} # link to the ns-3 core module and to the openssl libraries (crypto and ssl)
    )
endif()

Shelly R

unread,
Sep 4, 2022, 3:48:14 PM9/4/22
to ns-3-users
rtTrial.cc:40: undefined reference to `OPENSSL_init_crypto'
/usr/bin/ld: /home/ns-allinone-3.36.1/ns-3.36.1/scratch/NEW/CertTrial.cc:45: undefined reference to `BIO_s_file'
/usr/bin/ld: /home/ns-allinone-3.36.1/ns-3.36.1/scratch/NEW/CertTrial.cc:45: undefined reference to `BIO_new'
/usr/bin/ld: /home/ns-allinone-3.36.1/ns-3.36.1/scratch/NEW/CertTrial.cc:46: undefined reference to `BIO_new_fp'
/usr/bin/ld: /home/ns-allinone-3.36.1/ns-3.36.1/scratch/NEW/CertTrial.cc:51: undefined reference to `OBJ_txt2nid'
/usr/bin/ld: /home/ns-allinone-3.36.1/ns-3.36.1/scratch/NEW/CertTrial.cc:52: undefined reference to `EC_KEY_new_by_curve_name'
/usr/bin/ld: /home/ns-allinone-3.36.1/ns-3.36.1/scratch/NEW/CertTrial.cc:57: undefined reference to `EC_KEY_set_asn1_flag'
/usr/bin/ld: /home/ns-allinone-3.36.1/ns-3.36.1/scratch/NEW/CertTrial.cc:62: undefined reference to `EC_KEY_generate_key'
/usr/bin/ld: /home/ns-allinone-3.36.1/ns-3.36.1/scratch/NEW/CertTrial.cc:69: undefined reference to `EVP_PKEY_new'
/usr/bin/ld: /home/ns-allinone-3.36.1/ns-3.36.1/scratch/NEW/CertTrial.cc:70: undefined reference to `EVP_PKEY_assign'
/usr/bin/ld: /home/ns-allinone-3.36.1/ns-3.36.1/scratch/NEW/CertTrial.cc:63: undefined reference to `BIO_printf'
/usr/bin/ld: /home/ns-allinone-3.36.1/ns-3.36.1/scratch/NEW/CertTrial.cc:71: undefined reference to `BIO_printf'
/usr/bin/ld: CMakeFiles/scratch_NEW_Vehicle.dir/NEW/CertTrial.cc.o: in function `CT::generate_key()':
/home/ns-allinone-3.36.1/ns-3.36.1/scratch/NEW/CertTrial.cc:108: undefined reference to `EVP_PKEY_new'
/usr/bin/ld: /home/ns-allinone-3.36.1/ns-3.36.1/scratch/NEW/CertTrial.cc:118: undefined reference to `BN_new'
/usr/bin/ld: /home/ns-allinone-3.36.1/ns-3.36.1/scratch/NEW/CertTrial.cc:123: undefined reference to `BN_set_word'
/usr/bin/ld: /home/ns-allinone-3.36.1/ns-3.36.1/scratch/NEW/CertTrial.cc:131: undefined reference to `RSA_new'
/usr/bin/ld: /home/ns-allinone-3.36.1/ns-3.36.1/scratch/NEW/CertTrial.cc:132: undefined reference to `RSA_generate_key_ex'
/usr/bin/ld: /home/ns-allinone-3.36.1/ns-3.36.1/scratch/NEW/CertTrial.cc:134: undefined reference to `EVP_PKEY_assign'
/usr/bin/ld: /home/ns-allinone-3.36.1/ns-3.36.1/scratch/NEW/CertTrial.cc:137: undefined reference to `EVP_PKEY_free'



when i run my code in ns3.36.1 iam getting above errors. I done few changes in CMakeCache.txt file. But no changes same problem continuing

Gabriel Ferreira

unread,
Sep 4, 2022, 4:31:51 PM9/4/22
to ns-3-users
Do not change CMakeCache.txt. It gets refreshed automatically in case build settings change.
If you're in the scratch directory, change the ns-3.36.1/scratch/CMakeLists.txt file 

build_exec(
EXECNAME ${scratch_name}
EXECNAME_PREFIX ${target_prefix}
SOURCE_FILES "${source_files}"
LIBRARIES_TO_LINK "${ns3-libs}" "${ns3-contrib-libs}" ${OPENSSL_LIBRARIES} # all scratches will be linked to both ns3 modules and the SSL libraries
OUTPUT_DIRECTORY_PATH ${scratch_directory}/
)

Shelly R

unread,
Sep 5, 2022, 3:40:57 AM9/5/22
to ns-3-users
CMake Error at scratch/CMakeLists.txt:101 (build_exec):
  Unknown CMake command "build_exec".

The following lines showing above error:
build_exec(
EXECNAME ${scratch_name}
EXECNAME_PREFIX ${target_prefix}
SOURCE_FILES "${source_files}"
LIBRARIES_TO_LINK "${ns3-libs}" "${ns3-contrib-libs}" ${OPENSSL_LIBRARIES} # all scratches will be linked to both ns3 modules and the SSL libraries
OUTPUT_DIRECTORY_PATH ${scratch_directory}/
)

Gabriel Ferreira

unread,
Sep 5, 2022, 7:58:02 AM9/5/22
to ns-3-users
Oops, wrong macro. Build_exec should land in 3.37.

Try this one

target_link_libraries(
      ${target_prefix}${scratch_name} ${LIB_AS_NEEDED_PRE} "${ns3-libs}" "${ns3-contrib-libs}"
      "${ns3-external-libs}" "${OPENSSL_LIBRARIES}" {LIB_AS_NEEDED_POST}
    )

Jasmine Immaculate Shelly R

unread,
Sep 5, 2022, 2:53:15 PM9/5/22
to ns-3-...@googlegroups.com
i got this error 

CMake Error at scratch/CMakeLists.txt:118 (target_link_libraries):
  Cannot specify link libraries for target "scratch_" which is not built by
  this project.


when i give the following lines
target_link_libraries(
      ${target_prefix}${scratch_name} ${LIB_AS_NEEDED_PRE} "${ns3-libs}" "${ns3-contrib-libs}"
      "${ns3-external-libs}" "${OPENSSL_LIBRARIES}" {LIB_AS_NEEDED_POST}
    )



where i need to give /usr/local/lib path and lcrypto and lssl flags. 

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/cd141fdb-096f-41f0-8a1b-d596219f21ffn%40googlegroups.com.

Gabriel Ferreira

unread,
Sep 5, 2022, 4:08:44 PM9/5/22
to ns-3-users
You don't need to specify the library directory nor the library flags, it is handled by find_package(OpenSSL).
Now the problem is that ${scratch_name} is empty for some reason.
In case it was empty, it was supposed to break processing at https://gitlab.com/nsnam/ns-3-dev/-/blob/ns-3.36.1/scratch/CMakeLists.txt#L21

Would you mind removing this line, clearing the cache (./ns3 clean) then trying to reconfigure?

Shelly R

unread,
Sep 6, 2022, 2:40:52 PM9/6/22
to ns-3-users
Thank you i got the solution using find_package method and then added  ${OPENSSL_LIBRARIES} at right place. now the error gone .. thank u so much

Herman Nghidipaa

unread,
Sep 6, 2022, 4:25:24 PM9/6/22
to ns-3-users
I would like any one to help me with the codes  to this assessment
Untitled document.pdf

Samet Tonyalı

unread,
Oct 14, 2022, 6:41:02 PM10/14/22
to ns-3-users
Hi Shelly,

I've run into the same problem and couldn't find a solution for it. Would you mind sharing exact code/command excerpt you used to make it work with OpenSSL?

Thanks in advance,
Samet.

6 Eylül 2022 Salı tarihinde saat 21:40:52 UTC+3 itibarıyla Shelly R şunları yazdı:

Yoon Daehun

unread,
Jan 2, 2024, 12:39:05 AM1/2/24
to ns-3-users
Hello sir, Happy new year.

Im trying to link openssl with ns3. And removed the following lines (in CMakelist.txt) you said.

if(Not scratch_src)
   return()
endif()

But I have another error.

CMake Error at scratch/CMakeLists.txt:26 (get_filename_componenet):get_filename_component called with incorrect number of arguments Cmake (get_filename_component)

I was wondering if you have any idea to figure it out.

Thank you.

2022년 9월 6일 화요일 오전 5시 8분 44초 UTC+9에 Gabriel Ferreira님이 작성:
Reply all
Reply to author
Forward
0 new messages