Add external library to vs code c++ linux - c++

I'm trying to use libxl in my c++ project on visual studio code. This is my directory map:
├── ken.code-workspace
└── src
├── include
│ ├── AutoFilterA.h
│ ├── AutoFilterW.h
│ ├── BookA.h
│ ├── BookW.h
│ ├── enum.h
│ ├── FilterColumnA.h
│ ├── FilterColumnW.h
│ ├── FontA.h
│ ├── FontW.h
│ ├── FormatA.h
│ ├── FormatW.h
│ ├── FormControlA.h
│ ├── FormControlW.h
│ ├── handle.h
│ ├── libxl.h
│ ├── RichStringA.h
│ ├── RichStringW.h
│ ├── setup.h
│ ├── SheetA.h
│ └── SheetW.h
├── ken.cpp
└── lib
└── libxl.so
And this is my ken.cpp:
#include <iostream>
#include <vector>
#include <string>
#include "include/libxl.h"
using namespace std;
using namespace libxl;
int main()
{
cout << "Hello babe :)" << endl;
Book* book = xlCreateBook();
}
But I get these errors while trying to compile:
/run/media/mahdi/Mahdi/Projects/ken/src/ken.cpp:7:17: error: ‘libxl’ is not a namespace-name
7 | using namespace libxl;
| ^~~~~
/run/media/mahdi/Mahdi/Projects/ken/src/ken.cpp: In function ‘int main()’:
/run/media/mahdi/Mahdi/Projects/ken/src/ken.cpp:12:5: error: ‘Book’ was not declared in this scope
12 | Book* book = xlCreateBook();
| ^~~~
/run/media/mahdi/Mahdi/Projects/ken/src/ken.cpp:12:11: error: ‘book’ was not declared in this scope; did you mean ‘bool’?
12 | Book* book = xlCreateBook();
| ^~~~
| bool
I've never added an external library to visual studio code project before. Can I know what I'm doing wrong?

Related

Unison: Ignore files with Regex doesn't work

I tried to ignore some files that end with ".NUMBERS" like .133443. I tried this Regex but it still copies the files:
unison -batch -owner -group -times -ignore "Regex ^*\.[0-9]+$" /hadoop/bigdata/giin/data ssh://cnp31ginhortonen1.giin.recouv//hadoop/bigdata/giin/data -prefer newer`
Source :
[root#cnp31ginhortonen1 .unison]# tree /hadoop/bigdata/giin/data/
/hadoop/bigdata/giin/data/
├── aefd.csv
├── aefd.log
├── aefd.xml
├── subdir
│   ├── aefd.csv
│   ├── aefd.log
│   ├── aefd.xml
│   └── TB5E.B01.117.210409074
├── TB5E.B01.117.10409074
└── TB5E.B01.117.210409074

include path problem when building a simple library with bazel

The demo structure like this:
.
├── demo
│ ├── include
│ │ └── func.h
│ │
│ └── src
│ ├── BUILD
│ │
│ └── func.cc
└── WORKSPACE
func.h:
#pragma once
int square(int);
func.cc: include from the root
#include "demo/include/func.h"
int square(int i) { return i * i; }
BUILD:
cc_library(
name = "simple_demo",
srcs = ["func.cc"],
visibility = ["//visibility:public"],
)
Bazel build command in the dir of WORKSPACE:
bazel build //demo/src:simple_demo
The error occurs.
demo/src/func.cc:1:10: fatal error: 'demo/include/func.h' file not found
And I saw this in https://docs.bazel.build/versions/1.1.0/be/c-cpp.html#hdrs
All header files that are used in the build must be declared in the hdrs or srcs of cc_* rules. This is enforced.
However, if I add hdrs = "../include/func.h" to the BUILD, another error will occur
segment '..' not permitted
By default in Bazel labels are not allowed to cross the package boundaries. In your case func.h lives outside the package defined by the BUILD file, that is limited to demo/src (and sub-folders).
Assuming you're creating a library where func.h is the public header visible from outside, I would change the folder structure to:
.
├── demo
│ ├── include
│ │ └── func.h
│ ├── src
│ │ └── func.cc
│ └── BUILD
└── WORKSPACE
and the BUILD file to also include func.h:
cc_library(
name = "simple_demo",
hdrs = ["include/func.h"],
srcs = ["src/func.cc"],
visibility = ["//visibility:public"],
)
Notice that even with the suggested folder structure, if you don't include the hdrs = ... line (or don't include func.h in srcs = ..., if the header is not meant to be public), you will get an error for the reason you mentioned.
I am not sure if this might work, but can you try giving
'../include/func.h'
instead of 'demo/include/func.h' because I believe its not able to find a demo folder inside your src folder since it starts searching from there.

cmake can't find header file?

I am not sure I understand why I am having this problem..
but cmake seem to have some problems with finding the header file located in a different project.
tree view of my system:
tree
.
├─ build
├─ CMakeLists.txt
├─ src
├── CMakeLists.txt
├── include
│ ├── CMakeLists.txt
│ ├── database
│ │ ├── CMakeLists.txt
│ │ ├── database.cpp
│ │ └── database.h
│ ├── match
│ │ ├── CMakeLists.txt
│ │ ├── match.cpp
│ │ └── match.h
│ ├── record
│ │ ├── CMakeLists.txt
│ │ ├── record.cpp
│ │ └── record.h
│ └── spectogram
│ ├── CMakeLists.txt
│ ├── spectogram.cpp
│ └── spectogram.h
└── main.cpp
I’ve included the directory to the project which header files I am interested in, and also added the path in my
target_inlcude_directories. The problems is my database.h cannot see record.h.
database/CmakeLists.txt:
project(database)
MESSAGE(“In database CMAKELIST”)
#
# Build static library
add_library(database database.cpp database.h)
include_directories(${record_SOURCE_DIR} ${spectogram_SOURCE_DIR})
target_compile_features(database PUBLIC cxx_defaulted_functions)
target_include_directories(database PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${record_SOURCE_DIR} ${spectogram_SOURCE_DIR})
record/CMakeList.txt:
project(record)
MESSAGE( “In record CMAKELIST” )
# Include externalproject {portaudio} if lib/portaudio don't exist.
INCLUDE(ExternalProject)
ExternalProject_Add(project_portaudio
GIT_REPOSITORY https://git.assembla.com/portaudio.git
PREFIX lib/portaudio
UPDATE_COMMAND ""
CONFIGURE_COMMAND <SOURCE_DIR>/configure --enable-cxx
BUILD_IN_SOURCE 0
BUILD_COMMAND make
INSTALL_COMMAND sudo make install
)
ExternalProject_Get_Property(project_portaudio BINARY_DIR)
ExternalProject_Get_Property(project_portaudio SOURCE_DIR)
SET(portaudio_lib_dir "${BINARY_DIR}/lib/.libs")
SET(portaudio_inc_dir "${SOURCE_DIR}/include")
add_library(record STATIC record.cpp record.h AudioFile.cpp AudioFile.h)
add_library(portaudio STATIC IMPORTED)
set_target_properties(portaudio PROPERTIES
IMPORTED_LOCATION "${portaudio_lib_dir}/libportaudio.so")
set_property(TARGET portaudio APPEND PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${SOURCE_DIR}/include)
add_dependencies(portaudio project_portaudio) # Not sure if this is allowed for imported targets though
find_package(Threads REQUIRED)
find_package(ALSA REQUIRED)
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
SET(EXTRA_LIBS rt asound jack)
ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
#
# this makes sure we have compiler flags that allow class::class() = default (>= C++11)
target_link_libraries(record PUBLIC ${EXTRA_LIBS} ${ALSA_LIBRARIES} portaudio Threads::Threads )
target_compile_features(record PUBLIC cxx_defaulted_functions)
target_include_directories(record PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${project_portaudio})
The weird part is that it sometimes is able to compile, and other times it get stuck with this not able to find the header?
what could the problem be?

Bash filesname pattern detection and correction

I'm looking for the tools to detect a pattern in multiple files with the purpose to correct any heterogeneity. Precisely, this tool would help to generate the renaming scheme.
A correct pattern would be a mix of fixed patterns and increments followed by whatever and then an authorized extension.
Number of files ranges from 10 000 to 100 000, the solution should aim to minimize user intervention.
I have a directory like this :
testDir/
├── corrupttestfile100.ext
├── testfil0000.ext
├── testfil0001.ext
├── testfil0002.ext
├── testfil0003.ext
├── testfil0004.ext
├── testfil0005.ext
├── testfil0006.ext
├── testfil0007.ext
├── testfil0008.ext
├── testfil0009.ext
├── testfile010.ext
├── testfile011.ext
├── testfile012.ext
├── testfile013.ext
├── testfile014.ext
├── testfile015.ext
├── testfile016.ext
├── testfile017.ext
├── testfile018.ext
├── testfile019.ext
├── testfile020.ext
├── testfile021.ext
├── testfile022.ext
├── testfile023.ext
├── testfile024.ext
├── testfile025.ext
├── testfile026.ext
├── testfile027.ext
├── testfile028.ext
├── testfile029.ext
├── testfile030.ext
├── testfile031.ext
├── testfile032.ext
├── testfile033.ext
├── testfile034.ext
├── testfile035.ext
├── testfile036.ext
├── testfile037.ext
├── testfile038.ext
├── testfile039.ext
├── testfile040.ext
├── testfile041.ext
├── testfile042.ext
├── testfile043.ext
├── testfile044.ext
├── testfile045.ext
├── testfile046.ext
├── testfile047.ext
├── testfile048.ext
├── testfile049.ext
├── testfile050.ext
├── testfile051.ext
├── testfile052.ext
├── testfile053.ext
├── testfile054.ext
├── testfile055.ext
├── testfile056.ext
├── testfile057.ext
├── testfile058.ext
├── testfile059.ext
├── testfile060.ext
├── testfile061.ext
├── testfile062.ext
├── testfile063.ext
├── testfile064.ext
├── testfile065.ext
├── testfile066.ext
├── testfile067.ext
├── testfile068.ext
├── testfile069.ext
├── testfile080.ext
├── testfile081.ext
├── testfile082.ext
├── testfile083.ext
├── testfile084.ext
├── testfile085.ext
├── testfile086.ext
├── testfile087.ext
├── testfile088.ext
├── testfile089.ext
├── testfile090.ext
├── testfile091.ext
├── testfile092.ext
├── testfile093.ext
├── testfile094.ext
├── testfile095.ext
├── testfile096.ext
├── testfile097.ext
├── testfile098.ext
├── testfile099.ext
├── testfile101.ext2
└── testfileNotRelevant.ext
And I'd like to have the adequate tools to produce following feedback or equivalent :
1. pattern ^testfil matching 92/93
Exception :
corrupttestfile100.ext
2. pattern ^testfile matching 82/93
Exception :
corrupttestfile100.ext
testfil0000.ext
testfil0001.ext
testfil0002.ext
testfil0003.ext
testfil0004.ext
testfil0005.ext
testfil0006.ext
testfil0007.ext
testfil0008.ext
testfil0009.ext
3. Increment pattern breaks [70-79]
4. Increment pattern 3 digits 92/93
5. Increment pattern 4 digits 10/93
6. Extension exception : ext2 1/93
I began to scrip in bash using grep, find, sed and rename as it seemed natural but I'm wondering if will hit some walls and if I'm reinventing the wheel. I don't seem to find any relevant source of help and similar existing tools aren't open source nor data agnostic.

Connecting to ClojureScript bREPL: clojure.browser.repl/connect throws TypeError in compiled JavaScript

I'm trying to connect to a ClojureScript browser REPL, and I'm having trouble with clojure.browser.repl/connect. My compiled JavaScript throws a TypeError trying to call appendChild on a null object in the block of Google Closure code at the top. I'm following the instructions in ClojureScript: Up and Running (Chapter 9, p.78, available in the preview), and wondering if the tooling for this has changed since it was published.
I'm using Leiningen 2.0.0, Java 1.6.0_37, OS X 10.7.5, plus the dependencies in my project.clj:
(defproject brepl-hello "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.4.0"]
[org.clojure/clojurescript "0.0-1552"]
[compojure "1.1.5"]
[ring/ring-jetty-adapter "1.1.8"]]
:plugins [[lein-cljsbuild "0.3.0"]]
:source-paths ["src/clj"]
:cljsbuild {:builds [{
:source-paths ["src/cljs"]
:compiler {
:output-to "resources/public/brepl-hello.js"
:optimizations :whitespace
:pretty-print true}}]})
Here's the only ClojureScript source file, src/cljs/brepl_hello/brepl-hello.cljs:
(ns brepl-hello
(:require [clojure.browser.repl :as repl]))
(repl/connect "http://localhost:9000/repl")
This compiles to the file resources/public/brepl-hello.js, which I've inserted into index.html in the same directory:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="brepl-hello.js"></script>
</head>
<body>
</body>
</html>
I've been serving this on port 3000 with Ring/Jetty from the REPL or Python SimpleHTTPServer. When I open this page in Chrome, the dev console shows Uncaught TypeError: Cannot call method 'appendChild' of null, with a traceback to this if/else block in the Google Closure code at the top of the complied js file, where parentElm (passed in to the containing function as a parameter) is null.
if(goog.userAgent.GECKO || goog.userAgent.WEBKIT) {
window.setTimeout(goog.bind(function() {
parentElm.appendChild(iframeElm);
iframeElm.src = peerUri.toString();
goog.net.xpc.logger.info("peer iframe created (" + iframeId + ")")
}, this), 1)
}else {
iframeElm.src = peerUri.toString();
parentElm.appendChild(iframeElm);
goog.net.xpc.logger.info("peer iframe created (" + iframeId + ")")
}
This seems to be a problem with clojure.browser.repl/connect. Swapping out this line in the ClojureScript source for something like:
(ns brepl-hello
(:require [clojure.browser.repl :as repl]))
(.write js/document "Hello World!")
Will compile and run in the browser just fine. I suspect something is misconfigured in my build settings or directory structure, or I'm making a noob mistake somewhere in all this. What's changed since the time the instructions I'm following were published? I found a couple references to this problem in the #clojure irc logs, but no solution.
Finally, here's an abbreviated directory tree for reference:
├── out
│   ├── cljs
│   │   ├── core.cljs
│   │   └── core.js
│   ├── clojure
│   │   └── browser
│   │   ├── event.cljs
│   │   ├── event.js
│   │   ├── net.cljs
│   │   ├── net.js
│   │   ├── repl.cljs
│   │   └── repl.js
│   └── goog
│   └── [...]
├── pom.xml
├── project.clj
├── resources
│   └── public
│   ├── brepl-hello.js
│   └── index.html
├── src
│   ├── clj
│   │   └── brepl_hello
│   │   └── core.clj
│   └── cljs
│   └── brepl_hello
│   └── brepl-hello.cljs
└─── target
   ├── brepl-hello-0.1.0-SNAPSHOT.jar
   ├── classes
   ├── cljsbuild-compiler-0
   │   ├── brepl_hello
   │   │   └── brepl-hello.js
    │   ├── cljs
   │   │   ├── core.cljs
   │   │   └── core.js
    │   └── clojure
   │   └── browser
   │   ├── event.cljs
   │   ├── event.js
   │   ├── net.cljs
   │   ├── net.js
    │   ├── repl.cljs
    │   └── repl.js
   └── stale
   └── extract-native.dependencies
Well, its open source and looking at the code it seems that document.body is null at the time the repl hidden iframe is being added to it (the connect call leads to this point).
You should do this connect call on dom ready or body on load and it should work fine.
Take a look at:
https://github.com/magomimmo/modern-cljs/blob/master/doc/tutorial-02.md
or, for a better brepl experience, here
https://github.com/magomimmo/modern-cljs/blob/master/doc/tutorial-18.md