How to include .a file in PLatformIO? - c

When I build my project a static library .a file is created (libtest.a).
How can I use this library in other projects?
Folder structure:
|--lib
| |--test
| | |- test.c
| | |- test.h
|
|- platform.ini
|
|--src
| |- main.c
|
|--.pio
| |--build
| | |--genericSTM32F103RB
| | | |--lib704
| | | | |- libtest.a
Is it possible to use libtest.a in other projects and have the same functions?

Related

Excluding the transitive com.google.http-client:google-http-client:1.42.1 child dependency from included dependencies in Gradle

I'm facing this weird java.lang.NoSuchMethodError in my Groovy project, and I have it pretty much down to that there's some transitive grand-child dependency, that is being included by multiple child dependencies (below is just the compileClasspath):
compileClasspath - Compile classpath for source set 'main'.
+--- com.github.javafaker:javafaker:1.0.2
| +--- org.apache.commons:commons-lang3:3.5
| +--- org.yaml:snakeyaml:1.23
| \--- com.github.mifmif:generex:1.0.2
| \--- dk.brics.automaton:automaton:1.11-8
+--- com.google.apis:google-api-services-gmail:v1-rev20220404-2.0.0
| \--- com.google.api-client:google-api-client:2.0.0
| +--- com.google.oauth-client:google-oauth-client:1.34.1
| | _+--- com.google.http-client:google-http-client:1.42.0 -> 1.42.1_
| | | +--- org.apache.httpcomponents:httpclient:4.5.13
| | | | +--- org.apache.httpcomponents:httpcore:4.4.13 -> 4.4.15
| | | | +--- commons-logging:commons-logging:1.2
| | | | \--- commons-codec:commons-codec:1.11
| | | +--- org.apache.httpcomponents:httpcore:4.4.15
| | | +--- com.google.code.findbugs:jsr305:3.0.2
| | | +--- com.google.guava:guava:30.1.1-android -> 31.1-jre
| | | | +--- com.google.guava:failureaccess:1.0.1
| | | | +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
| | | | +--- com.google.code.findbugs:jsr305:3.0.2
| | | | +--- org.checkerframework:checker-qual:3.12.0
| | | | +--- com.google.errorprone:error_prone_annotations:2.11.0
| | | | \--- com.google.j2objc:j2objc-annotations:1.3
| | | +--- com.google.j2objc:j2objc-annotations:1.3
| | | +--- io.opencensus:opencensus-api:0.31.1
| | | | \--- io.grpc:grpc-context:1.27.2
| | | \--- io.opencensus:opencensus-contrib-http-util:0.31.1
| | | +--- io.opencensus:opencensus-api:0.31.1 (*)
| | | \--- com.google.guava:guava:29.0-android -> 31.1-jre (*)
| | +--- com.google.http-client:google-http-client-gson:1.42.0 -> 1.42.1
| | | _+--- com.google.http-client:google-http-client:1.42.1 (*)_
| | | \--- com.google.code.gson:gson:2.9.0
| | \--- com.google.guava:guava:31.1-android -> 31.1-jre (*)
| +--- com.google.http-client:google-http-client-gson:1.42.1 (*)
| +--- com.google.guava:guava:31.1-jre (*)
| +--- com.google.http-client:google-http-client-apache-v2:1.42.1
| | _+--- com.google.http-client:google-http-client:1.42.1 (*)_
| | +--- org.apache.httpcomponents:httpclient:4.5.13 (*)
| | \--- org.apache.httpcomponents:httpcore:4.4.15
| +--- org.apache.httpcomponents:httpcore:4.4.15
| +--- org.apache.httpcomponents:httpclient:4.5.13 (*)
| \--- _com.google.http-client:google-http-client:1.42.1 (*)_
\--- org.codehaus.groovy:groovy-all:2.4.7
My build.gradle looks like this :
plugins {
id 'java'
id "com.katalon.gradle-plugin" version "0.1.1"
}
repositories {
mavenCentral()
}
dependencies {
implementation 'com.github.javafaker:javafaker:1.0.2'
implementation 'com.google.apis:google-api-services-gmail:v1-rev20220404-2.0.0'
}
Notice that there are multiple instances of this com.google.http-client:google-http-client:1.42.1 across different child dependencies!
I try to get rid of those transitive dependencies with:
configurations.all {
exclude group: 'com.google.http-client', module: 'google-http-client'
}
but then my compileClasspath looks like:
compileClasspath - Compile classpath for source set 'main'.
+--- com.github.javafaker:javafaker:1.0.2
| +--- org.apache.commons:commons-lang3:3.5
| +--- org.yaml:snakeyaml:1.23
| \--- com.github.mifmif:generex:1.0.2
| \--- dk.brics.automaton:automaton:1.11-8
+--- com.google.apis:google-api-services-gmail:v1-rev20220404-2.0.0
| \--- com.google.api-client:google-api-client:2.0.0
| +--- com.google.oauth-client:google-oauth-client:1.34.1
| | +--- com.google.http-client:google-http-client-gson:1.42.0 -> 1.42.1
| | | \--- com.google.code.gson:gson:2.9.0
| | \--- com.google.guava:guava:31.1-android -> 31.1-jre
| | +--- com.google.guava:failureaccess:1.0.1
| | +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
| | +--- com.google.code.findbugs:jsr305:3.0.2
| | +--- org.checkerframework:checker-qual:3.12.0
| | +--- com.google.errorprone:error_prone_annotations:2.11.0
| | \--- com.google.j2objc:j2objc-annotations:1.3
| +--- com.google.http-client:google-http-client-gson:1.42.1 (*)
| +--- com.google.guava:guava:31.1-jre (*)
| +--- com.google.http-client:google-http-client-apache-v2:1.42.1
| | +--- org.apache.httpcomponents:httpclient:4.5.13
| | | +--- org.apache.httpcomponents:httpcore:4.4.13 -> 4.4.15
| | | +--- commons-logging:commons-logging:1.2
| | | \--- commons-codec:commons-codec:1.11
| | \--- org.apache.httpcomponents:httpcore:4.4.15
| +--- org.apache.httpcomponents:httpcore:4.4.15
| \--- org.apache.httpcomponents:httpclient:4.5.13 (*)
\--- org.codehaus.groovy:groovy-all:2.4.7
There's NO instances of the com.google.http-client:google-http-client:1.42.1 ANYWHERE! It also doesn't resolve the Error.
java.lang.NoSuchMethodError: com.google.api.client.http.HttpTransport.isMtls()Z
at com.google.api.services.gmail.Gmail$Builder.chooseEndpoint(Gmail.java:11179)
at com.google.api.services.gmail.Gmail$Builder.<init>(Gmail.java:11212)
at com.signaturemd.utils.GmailQuickstart.GetLabels(GmailQuickstart.groovy:72)
at com.signaturemd.utils.GmailQuickstart$GetLabels.call(Unknown Source)
at SMDEmailUtils.run(SMDEmailUtils:6)
What should I do to make sure that only ONE instance of com.google.http-client:google-http-client:1.42.1 is in the project, and that this Error goes away?
When you are saying "multiple instances" of the dependency what do you mean? I would assume you are confused by seeing multiple versions of the same dependency in the dependency graph.
But that has nothing to do with how many physical instances (jar files) will be packed up into the resulting artifact of your own. There is always just one physical instance of any dependency in the resulting artifact managed by either Gradle or Maven. However, if there are multiple different versions of the same dependency in the dependency graph they both choose the most appropriate version of that one physical instance as they see fit:
Gradle
In case of conflict, Gradle by default uses the newest of conflicting versions.
Maven
Dependency mediation - this determines what version of an artifact will be chosen when multiple versions are encountered as dependencies. Maven picks the "nearest definition". That is, it uses the version of the closest dependency to your project in the tree of dependencies. You can always guarantee a version by declaring it explicitly in your project's POM. Note that if two dependency versions are at the same depth in the dependency tree, the first declaration wins.
And you can override that version. So, in case of Gradle, instead of configuration.all { exclude {...} } that excludes the dependency from everywhere you can try configuring the resolutionStrategy like this:
configuration.all {
resolutionStrategy {
force "com.google.http-client:google-http-client:1.42.1"
}
}
That would (snippet from the doc below):
Allows forcing certain versions of dependencies, including transitive dependencies
This is what you need as per your original question. Like obviously, you don't want to exclude the dependency but rather you want to enforce the specific version of it.
For more info you can refer to the official documentation:
https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html
https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html#org.gradle.api.artifacts.ResolutionStrategy:force(java.lang.Object[])

How to add library headers to common scope

I have following project structure:
Project
|-include
| |-somedir
| | |-someheader.h
|-src
| |-somedir
| | |-somesource.c
| | |-CMakeLists.txt
| |-main.c
| |-CMakeLists.txt
|-lib
| |-somelib
| | |-include
| | | |-somelibheader.h
| | |-src
| | | |-somelibsource.c
| | | |-CMakeLists.txt
| | |-CMakeLists.txt
| |-CMakeLists.txt
|-CMakeLists.txt
Project/CMakeLists.txt:
cmake_minimum_required(VERSION 3.13)
set(CMAKE_C_STANDARD 11)
project(Project)
list(APPEND INCLUDES ${CMAKE_SOURCE_DIR}/include) # Contains all headers will be add to target
set(LIBRARIES_ROOT ${CMAKE_SOURCE_DIR}/lib)
set(SOURCES_ROOT ${CMAKE_SOURCE_DIR}/src)
add_subdirectory(${LIBRARIES_ROOT})
add_subdirectory(${SOURCES_ROOT})
Project/src/CMakeLists.txt:
add_executable(${CMAKE_PROJECT_NAME} main.c)
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${INCLUDES}) # adding headers
target_link_libraries(${CMAKE_PROJECT_NAME} ${LIBRARIES}) # linking libraries
add_subdirectory(somedir)
Project/src/somedir/CMakeLists.txt:
target_sources(${CMAKE_PROJECT_NAME} PRIVATE somesource.c)
Project/lib/CMakeLists.txt:
add_subdirectory(somelib)
Project/lib/somelib/CMakeLists.txt:
add_library(somelib)
target_include_directories(somelib PRIVATE include)
list(APPEND INCLUDES include) # Adding lib headers to be included to target
list(APPEND LIBRARIES somelib) # Adding lib to be linked to target
add_subdirectory(src)
Project/lib/somelib/src/CMakeLists.txt:
target_sources(somelib PRIVATE somelibsource.c)
In main.c project headers are able to be included, like #include <somedir/someheader.h>, but library header doesn't. It requires relative to main.c path, like #include "../lib/somelib/include/somelibheader.h". How to fix it and add library headers to common scope?

makefile prerequisites rebuild failed when using .d-dependencies-file

As pleased i recreated this Question to give my actual example:
My Problem is, when httpd-fsdata-erw.h is missing at the very first build the rule httpd-fsdata-erw.h:: creates it for me and erverything works fine.
If i touch httpd-fsdata-erw.h make recognised it and is building sourcefile1.o, sourcefile2.o and everything else neede again. Wonderful!
But when i delete httpd-fsdata-erw.h it. Make is checking the prerequisites and does nothing because it said "nothing to be done" although httpd-fsdata-erw.h is missing.
Now when i touch sourcefile2.h make can't find a rule to make target httpd-fsdata-erw.h.
MAYBE i mixed up some error-messages
I can fix it with the .PONY:-target, but as you know every turn it will rebuild most of the stuff.
File-Overview:
extension
|
|-- Makefile
|--(httpd-fsdata-erw.h) (created by perl
|--(httpd-fsdata-erw.c) (created by perl)
|--(httpd-fsdata-erw.o)
|-- ext.o
|-- ext.bin
TOPDIR-- Makefile
|-- obj_dir
| |--sourcefile1.o
| |--sourcefile1.d
| |--sourcefile2.o
| |--sourcefile2.d
| |--...
|
|-- app
| |
| |--sourcefile1.c (needs httpd-fsdata-erw.h)
| |--sourcefile2.c
| |--sourcefile2.h (needs httpd-fsdata-erw.h)
| |--sourcefile3.c
| |--sourcefile4.c
| |
| |--appskt
| | |--webserver
| | | |-- Makefile
| | | |...
| | | |--fsdata
| | | |--index.html
| | | |--somejavascript.js
| | |
| | |
| | |--shell
| | | |...
| | |--crypto
| | | |...
| | |--ftp
| | | |...
| | |
|
|
|-- contiki
| |--Makefile.include
|
|
|
|-- plattform
| |-- cpu
| | |-- Makefile.r7s7210
| | |
| | |
The Makefile in directory=webserver creates with a perl-script httpd-fsdata-erw.h .c and .o to the extension-folder with the rule
HTTPD_FSDATA_ERW_FILES=httpd-fsdata-erw.c httpd-fsdata-erw.h
$(HTTPD_FSDATA_ERW_FILES): $(PATH_WEBSERVER)/index.html $(PATH_WEBSERVER)/somejavascript.js
perl makefsdata -d $(HT....
web_content: $(HTTPD_FSDATA_ERW_FILES)
TOPDIR-- Makefile:
include $(CONTIKI)/Makefile.include
all: project.bin
project.bin: $(somestuff1) $(somestuff2) $(TARGET_PATH)/$(CONTIKI_PROJECT).$(TARGET)
#cmd .... nothing important, just a windows batch-file
|-- contiki--Makefile.include:
-include $(PATH_...)/Makefile.r7s7210
-include ${addprefix $(OBJECTDIR)/,$(CONTIKI_SOURCEFILES:.c=.d) \
$(PROJECT_SOURCEFILES:.c=.d)}
#.PHONY: httpd-fsdata-erw.h
httpd-fsdata-erw.h::
#$(MAKE) -j1 $(EXT_BIN) -C $(EXT_PATH) -f Makefile
$(TARGET_PATH)/%.$(TARGET): %.co $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a
some linking stuff
|-- plattform -- cpu -- Makefile.r7s7210:
$(OBJECTDIR)/%.o: %.c | $(OBJECTDIR):
...
$(CC) $(CFLAGS) $(IAR_INCLUDES) ... $< --dependencies=n $(#:.o=.d) -o $#)
But when i delete the "missing.h"-file after the very first build, make is unable to find a target.
Is this because of the structure of the .d-file?
It is.
To fix that, use -MP gcc command line switch when generating the .d file:
-MP This option instructs CPP to add a phony target for each dependency
other than the main file, causing each to depend on nothing. These
dummy rules work around errors make gives if you remove header
files without updating the Makefile to match. This is typical output:
test.o: test.c test.h
test.h:

How to Structure React and bootstrap-react projects?

How to Structure React and bootstrap-react projects?
Here you can see my folder structure. Is this the best practice?
|-COPYRIGHT.md
|-dist
| |-app
| |-bundle.js
| |-bundle.js.map
|
|-index.html
|-.git
|-.gitignore
|- node_modules
|-package.js
|-README.md
|
|-src
| |-app
| | |-components
| | | |-Footer.js
| | | |-Header.js
| | | |-Home.js
| | |
| | |-index.js
| |
| |-css
| | |-bootstrap.min.css
| | |-footer.css
| | |-header.css
| | |-styles.css
| |
| |-fonts
| | |-glyphicons-halflings
| |
| |-images
| | |-logo.jpg
| |
| |-index.html
| |
| |-js
| | |-es5-sham.min.js
| | |-es5-shim.min.js
| | |-html5shiv.min.js
| | |-html5shiv-printshiv.min.js
| | |-react-bootstrap.js
| | |-react-bootstrap.min.js
|
|-webpack.config.js
In the next step I would make my homepage multilingual. I need three languages de, en, fr.
I would like separate the languages like this.
How to change the languages in the Navbar?
Which of you has something already programmed and sends me a link of his Github repository? How do I program the routes correctly? In Footer I'll use three images as a flag for switching languages. But to be recognized by the browser language principle.
|-Languanges
|-de
| |-Impressum.js
|
|-en
| |-Imprint.js
|
|-fr
| |-empreinte.js

Copy multiple files to its subfolders

MainFolder
|
|--- Folder1
| |
| |--- Extra
| |--- picture.jpg
|
|---Folder2
| |
| |--- Extra
| |--- picture.jpg
|---Folder3
| |
| |--- Extra
| |--- picture.jpg
|---Folder4
| |
| |--- Extra
| |--- picture.jpg
I'm using Windows 10.I want to place a batch-file into the "MainFolder"-folder and execute it from there. It should copy every file named picture.jpg into its "Extra" folder.

Resources