Started playing with Clojure yesterday.
I can't get around how the module system works:
I have installed cursive
I have created a project following the leiningen template
I have two clojure files under /src/clojure_first_steps
core.clj
(ns clojure-first-steps.core)
(:require [clojure-first-steps.utils :refer :all])
(defn run-other-foo
(foo-2 ["hello"]))
utils.clj
(ns clojure-first-steps.utils)
(defn foo-2 [x] (x))
although 'lein compile' runs without probs, 'lein test' fails to compile on
(:require [clojure-first-steps.utils :refer :all]), the test being:
(ns clojure-first-steps.core-test
(:require [clojure.test :refer :all]
[clojure-first-steps.core :refer :all]))
(deftest a-test
(testing "I can access dependecies from another module"
(is (= "hello" (run-other-foo)))))
The error message is java.lang.ClassNotFoundException: clojure-first-steps.utils
EDIT: Project tree
.
├── CHANGELOG.md
├── clojure_first_steps.iml
├── doc
│ └── intro.md
├── LICENSE
├── project.clj
├── README.md
├── resources
├── src
│ ├── clojure_first_steps
│ │ ├── core.clj
│ │ └── utils.clj
├── target
│ ├── classes
│ │ └── META-INF
│ │ └── maven
│ │ └── clojure_first_steps
│ │ └── clojure_first_steps
│ │ └── pom.properties
│ ├── repl-port
│ └── stale
│ └── leiningen.core.classpath.extract-native-dependencies
└── test
├── clojure_first_steps
│ └── core_test.clj
In your core.clj:
(ns clojure-first-steps.core)
(:require [clojure-first-steps.utils :refer :all])
This is incorrect - the (:require) clause needs to be inside the ns macro. Because it is not, the symbols in the vector are looked up (and obviously not found).
(ns clojure-first-steps.core
(:require [clojure-first-steps.utils :refer :all]))
This tells the Clojure compiler to load clojure-first-steps.utils (if it has not already), and refer it's definitions in your newly created namespace.
Related
I'm doing some experiments to learn CMake. So the commands stay in my mind. I created a project to test what I just learned. However, I have a problem.
The structure of my project is as follows:
├── bin
├── CMakeLists.txt
└── src
├── Configuration
│ ├── CMakeLists.txt
│ ├── Test
│ │ └── TestConfiguration.h
├── Array
│ └── Array.h
├── CMakeLists.txt
├── Test2
│ ├── CMakeLists.txt
│ ├── Test2.cpp
│ ├── Test2.h
│ └── Test2-1.h
├── Main
│ ├── CMakeLists.txt
│ ├── Config.h
│ └── Main.h
├── Test3
│ ├── CMakeLists.txt
│ ├── Time.h
│ ├── Timer
│ │ ├── CMakeLists.txt
│ │ ├── Iterate.h
│ │ ├── Run.h
│ │ ├── Serial.cmpl.cpp
│ │ └── Serial.h
│ ├── Smart.h
│ ├── Counting.h
│ ├── Mute.h
│ └── MainTest.h
└── Utilities
├── CMakeLists.txt
├── Inform.h
├── Settings.h
├── Print.h
└── Const.h
But I didn't understand how I should make these CMakeLists.txt files. For example, the file src/Utilities/Inform.h uses the following header:
// src/Utilities/Inform.h
#include "Main/Config.h"
I've tried everything I've seen on the internet and stackoverflow to edit the src/Utilities/CMakeLists.txt file. But no matter what I do, it never sees the Main/Config.h file. I just need to do something like ../../Main/Config.h.
The same problem applies to other folders. What I want to learn here is to be able to navigate and call all files in the project with CMakeLists.txt. While doing this, I tried many of the following parameters:
add_library
target_include_directories
target_link_libraries
link_directories
link_libraries
I think there's something I'm missing or misunderstood. I would be glad if you help me in this regard. If you tell me how to edit the src/Utilities/CMakeLists.txt file, I will try to fill the others accordingly.
Additionally, there is something I'm curious about. Do I also need to edit the src/CMakeLists.txt file? Or is it enough if I just edit for example src/Utilities/CMakeLists.txt?
Also, I don't know if it will be needed additionally, but I'm using cmake version 3.16.3. My development environment is an x86_64 20.04.1 Ubuntu-based Elementary OS.
I've read the official documentation for CMake 3.16 and the answers from fellow developers on StackOverFlow. I want to use the header file in the parent folder in a header in subdirectories. But many ways I've tried are wrong. There is always an error in the include path I entered. I want to learn from experienced developers what I did wrong.
OpenCV is installed from the source on my Linux (Ubuntu 18.04.6 LTS) machine. The path is a bit different i.e. /usr/local/<blah_blah> and the directory tree looks somewhat like this:
milan#my_machine:/usr/local/<blah_blah>$ tree -L 4
.
├── bin
│ ├── opencv_annotation
│ └── ...
├── include
│ └── opencv4
│ └── opencv2
│ ├── ...
│ ├── core
│ ├── core.hpp
│ ├── ...
│ └── ...
├── lib
│ ├── cmake
│ │ └── opencv4
│ │ ├── OpenCVConfig.cmake
│ │ └── ...
│ ├── ...
│ ├── libopencv_core.so -> libopencv_core.so.4.2
│ ├── libopencv_core.so.4.2 -> libopencv_core.so.4.2.0
│ ├── libopencv_core.so.4.2.0
│ ├── ...
│ ├── ...
│ ├── opencv4
│ │ └── 3rdparty
│ │ ├── ...
│ │ └── ...
│ ├── python2.7
│ │ └── dist-packages
│ │ └── cv2
│ └── python3.6
│ └── dist-packages
│ └── cv2
└── share
├── licenses
│ └── opencv4
│ ├── ...
│ └── ...
└── opencv4
├── ...
│ └── ...
├── ...
└── ...
I had a similar issue for PCL (Point Cloud Library) in the past and my answer/solution fixed that. So, I tried something similar:
In settings.json, I put:
"C_Cpp.default.includePath": [
"/usr/local/<blah_blah>/include/opencv4/opencv2/**",
"/usr/local/<blah_blah>/include/opencv4/opencv2/core",
"/usr/local/<blah_blah>/include/opencv4/opencv2/core/*",
"/usr/local/<blah_blah>/include/opencv4/opencv2/core/**"
],
and in the c_cpp_properties.json file, I put:
"includePath": [
"${workspaceFolder}/**",
"${default}"
],
However, doing this is not fixing the issue. C++ IntelliSense/autocomplete still does not work for OpenCV C++. So, how to fix this issue?
Sample Code:
Note1:
In cmake, /usr/local/<blah_blah>/include/opencv4 is used under include_directories.
Compilation and execution work fine.
Note2: the following questions/issues are different from mine:
VSCode autocomplete not working for OpenCV installed from source -- for OpenCV Python, not C++
cv2 (opencv-python) intellisense not working -- for OpenCV Python, not C++
It turned out that in my settings.json file, the includePaths were set like this:
"C_Cpp.default.includePath": [
"/usr/local/<blah_blah>/include/opencv4/opencv2/**",
"/usr/local/<blah_blah>/include/opencv4/opencv2/core.hpp",
"/usr/local/<blah_blah>/include/opencv4/opencv2/core",
.
.
],
However, in my code, the headers were included like:
#include <opencv2/core.hpp>
If the opencv2 folder needs to be included in the #include directive, the includePaths should look like this:
"C_Cpp.default.includePath": [
"/usr/local/<blah_blah>/include/opencv4",
.
.
],
So, the following includePaths configuration fixed the issue with IntelliSense/autocompletion for OpenCV:
"C_Cpp.default.includePath": [
"/usr/local/<blah_blah>/include/opencv4",
"/usr/local/<blah_blah>/include/opencv4/**",
],
For a detailed explanation, take a look into the issue (Issue 9900) I created on vscode-cpptools GitHub page, particularly this thread/reply.
Special thanks to vscode-cpptools and vscode-cmake-tools team!
I have found good documentations on this known problem of compiling Freetype related to Harfbuzz: http://www.gregwessels.com/dev/2017/05/02/freetype-harfbuzz.html and here 44184890
But they seem obsolet nowadays: freetype-2.9 with harfbuzz-1.7.6
Here is my way compiling:
download Freetype tarball
extract the tarball...
open builds\windows\vc2010\freetype.sln
it should already Generate well (as a dll)
download Harfbuzz
extract the tarball next to freetype...
run cmake ./ at root level to obtain a .sln
it must already Generate well (as lib)
At this point you have 2 separate libs not working together which means:
Freetype will not open GSUB scripts of your fonts. (or maybe I am wrong)
To do so, I need help! I also need confirmations!!!
Is seems to be needed to enable the use of Harfbuzz in Freetype at compile time; I have found a precompiler directive called FT_CONFIG_OPTION_USE_HARFBUZZ
But when activating it, I have some compile link errors when using both libs in a third project:
autofit.obj : error LNK2019: external symbol not found _hb_ft_font_create referenced in function _af_face_globals_new
Good to know, hb_ft_font_create is an extern function in harfbuzz.
So it seems to be a cyclic extern problem... I certainly don't have the good config at a point, but I have browsed many docs and helps, found nothing...
-- edit --
After both pojects decompression, you have normaly to obtain such a tree:
.
├── freetype-2.9
│ ├── autogen.sh
│ ├── builds
│ │ ├── ...
│ │ └── windows
│ │ └── vc2010 <<<< The .sln to use is in here
│ ├── CMakeLists.txt <<<< It is also good to obtain proper sln
│ ├── configure
│ ├── devel
│ │ ├── ft2build.h
│ │ └── ftoption.h
│ ├── include
│ │ ├── freetype
│ │ └── ft2build.h
│ ├── ...
│ ├── objs
│ │ ├── freetype.dll
│ │ ├── freetype.lib
│ │ ├── README
│ │ └── Win32
│ ├── README
│ ├── README.git
│ └── src
└── harfbuzz-1.7.6
├── ...
├── cmake_install.cmake
├── CMakeLists.txt <<<< The cmake project to obtain proper sln is this one
├── compile
├── ...
├── COPYING
├── CTestTestfile.cmake
├── Debug
│ ├── harfbuzz.lib
│ ├── harfbuzz-subset.lib
│ └── ...
├── depcomp
├── docs
├── gtk-doc.make
├── harfbuzz.sln
├── harfbuzz.vcxproj
├── ...
├── main.dir
│ └── Debug
├── NEWS
├── README
├── README.python
├── RELEASING.md
├── replace-enum-strings.cmake
├── RUN_TESTS.vcxproj
├── RUN_TESTS.vcxproj.filters
├── src
│ ├── *.hh
│ └── *.cc
├── test
├── THANKS
├── TODO
├── util
└── Win32
└── Debug
Or configure harfbuzz like --with-freetype=no --with-fontconfig=no to avoid circular deps...I think so anyway...
Just use https://github.com/Microsoft/vcpkg/ to install both and don't look back :) Both HarfBuzz and Freetype have a port there and are well supported.
About the cyclic dependency, FreeType to HarfBuzz dependency is not a must think to have. vcpkg handles HarfBuzz to FreeType dependency and that is what most project will need.
I created a new Clojurescript/Om project. The directory structure looks like this:
├── project.clj
├── resources
│ └── public
│ ├── index.html
│ └── src
│ └── om_tutorial
│ └── core.cljs
├── script
│ └── figwheel.clj
├── src
│ ├── clj
│ │ ├── test
│ │ └── example-project
│ │ └── core.clj
│ └── cljs
│ └── example-project
│ └── core.cljs
├── target
│ ├── classes
│ │ └── META-INF
│ │ └── maven
│ │ └── typing
│ │ └── typing
│ │ └── pom.properties
│ └── stale
│ └── leiningen.core.classpath.extract-native-dependencies
└── test
└── clj
└── example-project
└── test_core.clj
My package.json is very minimal, and it looks like this:
(defproject typing "0.1.0-SNAPSHOT"
:description "example-project"
:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/clojurescript "1.7.170"]
[org.omcljs/om "1.0.0-alpha22"]
[figwheel-sidecar "0.5.0-SNAPSHOT" :scope "test"]
[http-kit "2.2.0-SNAPSHOT"]
[compojure "1.5.0"]
[ring "1.4.0"]
[cheshire "5.5.0"]]
:test-paths ["test"])
However, I can't get Leiningen to recognize the test path. When I run lein test, I see:
Exception in thread "main" java.io.FileNotFoundException: Could not locate test/typing/test_core__init.class or test/example-project/test_core.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name., compiling:(/private/var/folders/dk/jvt798yj6ds6wnkwk_24wrcm0000gp/T/form-init5157365051258208935.clj:1:125)
...
Caused by: java.io.FileNotFoundException: Could not locate test/example-project/test_core__init.class or test/example-project/test_core.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.
...
Tests failed.
I moved the tests from test/clj/example-project/... to test/example-project/..., and the implementation from src/clj/example-project/ to src/example-project but I still see the same error.
How do I get Leiningen to recognize my tests?
Perhaps the :test-paths need to reach in further so that source code can be found by lein.
You could try:
:test-paths ["test/clj"]
I see you moved source code around using basically the same thinking. But this is easier. Also after any changes to project.clj you need to lein clean then lein deps. My way is more about the deps and yours more about the clean, but both regardless is expedient. Also you need to check that clean is actually getting rid of output. If it is not you can always manually clean by deleting files.
Is there any guide how to start with HTMLBars? I am following "building HTMLBars" section but finally I am stuck. I have run building tool and now I have files in my dist directory like this:
.
├── htmlbars-compiler.amd.js
├── htmlbars-runtime.amd.js
├── morph.amd.js
├── test
│ ├── htmlbars-compiler-tests.amd.js
│ ├── htmlbars-runtime-tests.amd.js
│ ├── index.html
│ ├── loader.js
│ ├── morph-tests.amd.js
│ ├── packages-config.js
│ ├── qunit.css
│ └── qunit.js
└── vendor
├── handlebars.amd.js
└── simple-html-tokenizer.amd.js
Which should I add to my ember project and is that all or have I to do something more? Is this library ready or it is still unusable for ember?
Not even close to ready yet, I'd love to give more info, but there really isn't any. Last I heard they wanted it as a beta in 1.9, but we'll see.