This question already has answers here:
What is the proper way to use `pkg-config` from `cmake`?
(6 answers)
Closed 1 year ago.
I am new to Cmake. I am using Ubuntu 20.
I build & installed dlt-daemon-2.18.8 locally (/home/map/third_party) and build Log library.
Following is the Content of Log library CMakeLists.txt
find_package(PkgConfig REQUIRED)
pkg_search_module(DLT automotive-dlt REQUIRED)
message("***** pkg_search_module DLT_MODULE_NAME = ${DLT_MODULE_NAME} *****")
message("***** pkg_search_module DLT_FOUND = ${DLT_FOUND} *****")
message("***** pkg_search_module DLT_LIBRARIES = ${DLT_LIBRARIES} *****")
message("***** pkg_search_module DLT_LINK_LIBRARIES = ${DLT_LINK_LIBRARIES} *****")
message("***** pkg_search_module DLT_LIBRARY_DIRS = ${DLT_LIBRARY_DIRS} *****")
message("***** pkg_search_module DLT_LDFLAGS = ${DLT_LDFLAGS} *****")
message("***** pkg_search_module DLT_LDFLAGS_OTHER = ${DLT_LDFLAGS_OTHER} *****")
message("***** pkg_search_module DLT_INCLUDE_DIRS = ${DLT_INCLUDE_DIRS} *****")
add_subdirectory(src)
Following is the part of CMakeLists.txt in src folder which is in Log folder(main CMAke file)
target_link_libraries(${PROJECT_NAME}
PUBLIC
${DLT_LIBRARIES}
ara::core-types
apd::Threads
)
Following is the output from Log library CMakeLists.txt & it looks ok.
-- Checking for one of the modules 'automotive-dlt'
***** pkg_search_module DLT_MODULE_NAME = automotive-dlt *****
***** pkg_search_module DLT_FOUND = 1 *****
***** pkg_search_module DLT_LIBRARIES = dlt;rt;pthread *****
***** pkg_search_module DLT_LINK_LIBRARIES = /home/map/third_party/lib/libdlt.so;/usr/lib/x86_64-linux-gnu/librt.so;/usr/lib/x86_64-linux-gnu/libpthread.so *****
***** pkg_search_module DLT_LIBRARY_DIRS = /home/map/third_party/lib *****
***** pkg_search_module DLT_LDFLAGS = -L/home/map/third_party/lib;-ldlt;-lrt;-lpthread *****
***** pkg_search_module DLT_LDFLAGS_OTHER = *****
***** pkg_search_module DLT_INCLUDE_DIRS = /home/map/third_party/include/dlt;/home/map/third_party/include *****
-- Configuring done
After this, I am building 1 application & 2 Library using above mentioned Log library but it is failing to link with the following error
[100%] Linking CXX shared library libe2exf.so
/usr/bin/ld: cannot find -ldlt
[100%] Linking CXX shared library libe2e.so
/usr/bin/ld: cannot find -ldlt
[100%] Linking CXX executable execution-manager
/usr/bin/ld: cannot find -ldlt
If I install this two component (sudo apt-get install libdlt2 & sudo apt-get install libdlt-dev ) then 2 Libraries(libe2exf.so & libe2e.so) are building but failing application(execution-manager) with following error
/usr/bin/ld: /home/map/third_party/lib/libara_log.a(log_stream.cpp.o): in function ara::log::LogStream::operator<<(ara::core::Span<ara::core::internal::Byte const, 18446744073709551615ul>)':log_stream.cpp:(.text+0xbaf): undefined reference to dlt_user_log_write_sized_utf8_string'
/usr/bin/ld: /home/map/third_party/lib/libara_log.a(log_stream.cpp.o): in function ara::log::LogStream::WithLocation(ara::core::internal::basic_string_view<char, std::char_traits<char> >, int)':log_stream.cpp:(.text+0xdc6): undefined reference to dlt_user_log_write_sized_utf8_string'
I don't want to install libdlt2 & libdlt-dev and please let me know how to link above 1 application & 2 Library to /home/map/third_party/lib/libdlt.so;
Thanks in advanceHi,
I build & installed dlt-daemon-2.18.8 locally (/home/map/third_party) and build Log library.
Following is the Content of Log library CMakeLists.txt
find_package(PkgConfig REQUIRED)
pkg_search_module(DLT automotive-dlt REQUIRED)
message("***** pkg_search_module DLT_MODULE_NAME = ${DLT_MODULE_NAME} *****")
message("***** pkg_search_module DLT_FOUND = ${DLT_FOUND} *****")
message("***** pkg_search_module DLT_LIBRARIES = ${DLT_LIBRARIES} *****")
message("***** pkg_search_module DLT_LINK_LIBRARIES = ${DLT_LINK_LIBRARIES} *****")
message("***** pkg_search_module DLT_LIBRARY_DIRS = ${DLT_LIBRARY_DIRS} *****")
message("***** pkg_search_module DLT_LDFLAGS = ${DLT_LDFLAGS} *****")
message("***** pkg_search_module DLT_LDFLAGS_OTHER = ${DLT_LDFLAGS_OTHER} *****")
message("***** pkg_search_module DLT_INCLUDE_DIRS = ${DLT_INCLUDE_DIRS} *****")
Following is the output from Log library CMakeLists.txt & it looks ok.
-- Checking for one of the modules 'automotive-dlt'
***** pkg_search_module DLT_MODULE_NAME = automotive-dlt *****
***** pkg_search_module DLT_FOUND = 1 *****
***** pkg_search_module DLT_LIBRARIES = dlt;rt;pthread *****
***** pkg_search_module DLT_LINK_LIBRARIES = /home/map/third_party/lib/libdlt.so;/usr/lib/x86_64-linux-gnu/librt.so;/usr/lib/x86_64-linux-gnu/libpthread.so *****
***** pkg_search_module DLT_LIBRARY_DIRS = /home/map/third_party/lib *****
***** pkg_search_module DLT_LDFLAGS = -L/home/map/third_party/lib;-ldlt;-lrt;-lpthread *****
***** pkg_search_module DLT_LDFLAGS_OTHER = *****
***** pkg_search_module DLT_INCLUDE_DIRS = /home/map/third_party/include/dlt;/home/map/third_party/include *****
-- Configuring done
After this I am building 1 application & 2 Library using above mentioned Log library but it is failing to link with following error
[100%] Linking CXX shared library libe2exf.so
/usr/bin/ld: cannot find -ldlt
[100%] Linking CXX shared library libe2e.so
/usr/bin/ld: cannot find -ldlt
[100%] Linking CXX executable execution-manager
/usr/bin/ld: cannot find -ldlt
If I install this two component (sudo apt-get install libdlt2 & sudo apt-get install libdlt-dev ) then 2 Libraries(libe2exf.so & libe2e.so) are building but failing application(execution-manager) with following error
/usr/bin/ld: /home/map/third_party/lib/libara_log.a(log_stream.cpp.o):
in function
ara::log::LogStream::operator<<(ara::core::Span<ara::core::internal::Byte const, 18446744073709551615ul>)':log_stream.cpp:(.text+0xbaf): undefined reference to dlt_user_log_write_sized_utf8_string'
/usr/bin/ld: /home/map/third_party/lib/libara_log.a(log_stream.cpp.o):
in function
ara::log::LogStream::WithLocation(ara::core::internal::basic_string_view<char, std::char_traits<char> >, int)':log_stream.cpp:(.text+0xdc6): undefined reference to dlt_user_log_write_sized_utf8_string'
I don't want to install libdlt2 & libdlt-dev and please let me know how to link above 1 application & 2 Library to /home/map/third_party/lib/libdlt.so;
I am using following cmake command to build. Please let me know if it is wrong.
cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DARA_ENABLE_TESTS=OFF \
-DIMPORTED_LOCATION=/home/manoj/third_party,/home/manoj/third_party/lib/pkgconfig \
-DINTERFACE_INCLUDE_DIRECTORIES=/home/manoj/third_party/include \
-DINCLUDE_DIRECTORIES=/home/manoj/third_party \
-DCMAKE_MODULE_PATH=/home/manoj/third_party/share/cmake-3.16/Modules \
-DCMAKE_PREFIX_PATH=/home/manoj/third_party \
-DCMAKE_INSTALL_PREFIX=/home/manoj/third_party \
-DCMAKE_BUILD_TYPE=Release ..
Thanks in advance
As far as I see, you only need to add the link directory to your target:
target_link_directories(${PROJECT_NAME}
PUBLIC
${DLT_LIBRARY_DIRS}
)
This is because DLT_LIBRARIES don't contain the path information about those libraries. The path information is contain in the directory variable.
You can see this in the DLT_LDFLAGS that linking require to add the directory before linking to the library.
An even better solution would be to use DLT's imported targets if it exports one, since it would take care of all of this by itself.
Related
I want to copy a folder with xcopy. However, as soon as I place the destination folder in the source folder, nothing is being copied anymore. Is there a workaround for this problem?
The idea is to generate a backup of an entire folder strucutre (source) into one subfolder. When executing xcopy I exclude the subfolder for the backup (destination), where my backups should be stored.
I have already tested my code and it works just fine as long as the destination folder does no lie within the source folder.
The code is written with VBA.
Function CopyFolder(ByVal sourcePath As String, ByVal destinationPath As String, ByVal excludeFile As String)
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
' /e -> copys all subfolders including empty ones; /k -> retains the read-only attribute if existend
wsh.Run "xcopy " & sourcePath & " " & destinationPath & " /e /k /exclude:" & excludeFile, vbNormalFocus, waitOnReturn
End Function
The code is being executed with no error, but when I check the destination folder, no files haven been copied.
this should not be possible since it should end with the error: "unable to execute a cyclic copy" or stuff like that.
if you want you can do something like this (one-liner):
FOR /F "usebackq delims=;" %A IN (`dir %sourcePath% /B /AD ^|FINDSTR /V "%destinationPath%"`) DO #xcopy "%sourcePath%\%A\*.*" "%destinationPath%\" /EK
if the SOURCE is filled with directories that you should copy in the DEST. subdirectory with all their files.
Pay Attention to:
... %A IN (**`** .... **`**) <---- theese are reverse quotes (alt+96)
... /AD **^**|FINDSTR /V <---- this CAP has to be written explicitly like this (but without asterisks, obvious)
%sourcePath% and %destinationPath% <--- This is the batch variable notation. Do your String concatenation magic here, since you're launching from inside a vba
Hope this helps you! :-)
Bye
i want to delete all files with extension ".c" in a folder from shell command in vba, below code i am not able to execute in VBA Macro. should there be any issue if folder name contains spaces in it or what changes should be done in code
all_C_Files = Selected_User_Output_Folder & "*.C"
Shell "cmd /c del /F" & all_C_Files
'Selected_User_Output_Folder = "C:\Users\Berater\Desktop\Config File Generator"
Why to use shell command at all when you can use Kill
Sub test()
Selected_User_Output_Folder = "C:\Users\Berater\Desktop\Config File Generator\*.c"
On Error Resume Next
Kill Selected_User_Output_Folder
End Sub
Always good practice to quote file/folder paths:
all_C_Files = Selected_User_Output_Folder & "*.C"
Shell "cmd /c del /F """ & all_C_Files & """"
I'm using below macro in goal of obtaining list of all files in folder :
Sub SO()
Const parentFolder As String = "C:\Users\bloggsj\folder\" '// change as required, keep trailing slash
Dim results As String
results = CreateObject("WScript.Shell").Exec("CMD /C DIR """ & parentFolder & "*.*"" /S /B /A:-D").StdOut.ReadAll
Debug.Print results
Ens Sub
but it gives me invalid output as it doesn't chandle Unicode characters, which are part of files names in my directory. In normal batch file I could use additional command 'CHCP 1250' to change coding page for symbols. But I can't incorpotrate it into above macro. I've tried in several ways like :
results = CreateObject("WScript.Shell").Exec("CMD /C CHCP 1250 DIR """ & parentFolder & "*.*"" /S /B /A:-D").StdOut.ReadAll
and
results = CreateObject("WScript.Shell").Exec("CMD /C ""CHCP 1250"" ""DIR """ & parentFolder & "*.*"" /S /B /A:-D""").StdOut.ReadAll
Ampersand
command1 & command2 : Use to separate multiple commands on one command
line. Cmd.exe runs the first command, and then the second command.
CMD /C CHCP 1250 & DIR ....
However VBA has native support for a directory listing and VBScript can use the FileSystemObject to achieve the same.
The line to launch the exe is :
Shell("""D:\glut\SB5\VisualStudio2008\Chapter06\TexturedTriangle\TexturedTriangle.exe"" """ & lat & " " & lng, vbNormalFocus)
And the texture is present at the same path in the function parameter.
I see only a triangle without any texture on executing the exe from output of vb code
also it says
The shader at TexturedIdentity.vp could not be found.
while the file is at the same path
What could be wrong ?
Shell command will launch an application with current process directory instead of your target exe directory.
To solve your problem: try to use System.Diagnostics.Process:
Dim exePath As String = "D:\parent\child\TexturedTriangle.exe"
Dim info As New ProcessStartInfo(exePath )
info.WorkingDirectory = IO.Path.GetDirectoryName(exePath)
info.Arguments = lat & " " & lng
Process.Start(info)
I am trying to add to my application some icons via the code.
When i run my executable from debug / release compilation folder it works good .
But when I move my executable files to other folders it tells me that it doesn't find the icon files .
Any idea how/where I should tell the compiler to add those files to my final executable version ,that they will be visible .
my code looks like that
Private Sub Set_Application_Icon()
Dim Current As String
Dim Parent As DirectoryInfo
'current path is /bin/solution/
Current = Directory.GetCurrentDirectory()
Parent = Directory.GetParent(Current)
ChDir(Parent.FullName)
'/bin
Current = Directory.GetCurrentDirectory()
Parent = Directory.GetParent(Current)
ChDir(Parent.FullName)
'icons located at current directory now
#If WizardVersion = 0 And ViewerVersion = 0 Then
Me.Icon = New Icon(CurDir() & "\" & "LP_V2009c.ico")
#ElseIf WizardVersion = 0 And ViewerVersion = 1 Then
Me.Icon = New Icon(CurDir() & "\" & "LP_V2009v.ico")
#Else
Me.Icon = New Icon(CurDir() & "\" & "LP_V2009.ico")
#End If
End Sub
thanks a lot for help
I suggest you look into adding icons as Resources, instead of referencing them as external files.
#If WizardVersion = 0 And ViewerVersion = 0 Then
Me.Icon = New Icon(CurDir() & "\" & "LP_V2009c.ico")
#ElseIf WizardVersion = 0 And ViewerVersion = 1 Then
Me.Icon = New Icon(CurDir() & "\" & "LP_V2009v.ico")
#Else
Me.Icon = New Icon(CurDir() & "\" & "LP_V2009.ico")
#End If
First, those are compile time conditional statements. Not sure if you were wanting that evaluated at compile time, or run time. Second, CurDir is considered unreliable in determining application directory. In VS 2008, you can use the application's My namespace (My.Application.Info.DirectoryPath), or use Reflection to get the application's path. Last, as a previous answerer mentioned, the most reliable/portable way to do this would be to add the icons to your project as embedded resources. Hope that helps.
EDIT: The last link that I posted (embedded resources) shows how to do that. Here is a method from that article that retrieves an embedded icon from the assembly using Reflection.
Function GetEmbeddedIcon(ByVal strName As String) As Icon
Return New Icon(System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(strName))
End Function
That should do it for you.