Error after implementing 'curl': E1696 cannot open source file "curl/curl.h" - c++

The title says it all. I'm using VS 2019 since as far as I can understand, curl is more used on VS 2019 rather than VS Code (correct me if I'm wrong). So my project has this structure:
── myproject
├── myproject
│ ├── src
│ │ ├── main.cpp
│ ├── myproject.vcxproj
│ ├── myproject.vcxproj.filters
│ └── myproject.vcxproj.user
├── externals
│ ├── curl [SUBMODULE]
│ │ ├── include [THE INCLUDE DIRECTORY]
│ │ │ ├─ ···
│ │ ├── ···
│ ├── ···
├── .git
├── .vs
├── .gitmodules
├── myproject.sln
I added curl (see https://github.com/curl/curl) as a Git submodule in the folder ./externals/curl:
2. In my solution, I went to the project 'myproject' -> (Right Click) -> Properties -> C/C++ -> General -> Additional Include Directories and added the following line:
$(SolutionDir)externals\curl\include -> Apply -> OK
I went to ./src/main.cpp and pressed View Code (F7), then added the line #include "curl/curl.h". But even after doing steps 1 and 2, VS 2019 won't detect the curl headers:
Consequently obtaining that error.

(Thanks to #drescherjm)
All you have to do is ensure you have applied the change in step #2 for all the configurations and platforms (go to the project 'myproject' -> (Right Click) -> Properties -> C/C++ -> General -> Additional Include Directories; in the top of the window, set 'Configurations' to "All Configurations" as well as 'Platforms' to "All Platforms"). See Image
You may want to apply these Include Directories only to one (or a few) of the configurations and/or platforms, so once you're done just set that(those) configuration(s) on your Visual Studio IDE.

Related

How to get unit tests (using CMake and GTest) to know where a folder of test data is?

I am using CMake and GTest to unit test a C++ program. One of my tests uses fopen() to open a file of test data.
I am struggling to figure out how to not get a "No such file or directory" error.
Directory Structure
├── CMakeLists.txt
├── build
├── src
│ └── myProgram.cxx
└── tests
├── CMakeLists.txt
├── data
│ ├── dataset1.txt
│ ├── dataset2.txt
│ ├── dataset3.txt
│ └── dataset4.txt
└── myProgramTests.cxx
Test Code
TEST(test, read_data_file) {
// Open test file
std::FILE *f = fopen("inputs/dataset1.txt", "r");
if (f == NULL){
perror ("Error opening file");
}
fclose(f);
}
This seems simple, but I can't figure out what to put here. I have tried "dataset1.txt", "inputs/dataset1.txt", "tests/inputs/dataset1.txt". What am I missing / is there a way for me into "include" these files via a line in CMakeLists.txt so I can just read them in with one of the strings I tried above?
Summary: How do I properly reference the location of files stored in a tests/data subdirectory within GTest?
Use ctest of cmake. Its add_test command has a useful property WORKING_DIRECTORY that are you looking for.
Paths that do not start with a / are relative to your current working directory, i.e the directory your shell is in when you run the tests.
For example, if your current working directory is the top-level directory of your project, then the relative path to dataset1.txt is tests/data/dataset1.txt

Share common test code between multiple packages in rust

I am having common functionality that I want to reuse in junit tests that live in different packages and I don't know how to do it. I've tried with different modules and libs but something is not working. My current structure looks something like this:
.
├── Cargo.lock
├── Cargo.toml
├── foo
│ └── bar
│ └── baz
│ ├── template
│ │ ├── Cargo.lock
│ │ ├── Cargo.toml
│ │ └── src
│ │ └── tests
│ │ ├── mod.rs
│ │ └── test1.rs
│ │
│ └── template_implementation
│ ├── Cargo.lock
│ ├── Cargo.toml
│ └── src
│ └── tests
│ ├── mod.rs
│ └── test2.rs
│
└── utils
└── testpackage
├── Cargo.toml
├── lib.rs
└── common.rs
So in common.rs I have something like this:
/// setup for tests
pub fn setup() { ... }
pub fn mock_x() { ... }
pub fn mock_y() { ... }
lib.rs looks like this:
#[cfg(test)]
pub mod common;
I want to use those functions in common.rs in both test1.rs and test2.rs. I made sure dependencies are correct on the cargo files, and even though they are "found" by the IDE, I get an error when doing cargo test that the methods are not found in testpackage.
It "works" if I remove #[cfg(test)] from the mod but I don't want that to be included when doing cargo build, besides I get bunch of warnings when running the tests and it doesn't even compile the artifacts then.
I tried moving common.rs around, to include it in the template package for example but still couldn't get it work, I face similar issues. Not sure if I am missing some annotation or what, if feels like a very silly issue.
How would you do something like this?
Just a hunch (I haven't tried to recreate your folder structure there and never tried to compile a #[cfg(test)] library), but by the way it looks you're juggling three different crates in a workspace setup. In this case your testpackage would (to my understanding) only be included as a pseudo-external dependency in your template and template_implementation crates. To my understanding of the workspaces build process, workspace sub-crates will be compiled for debug or release (but never in testing configuration) for inclusion in other sub-crates of a workspace, while #[cfg(test)] is only ever used within the scope of a single crate.

Can I have source code ouside project folder in xcode?

I just created my first xcode C++ project. Directory structure looks like the following:
myproject
+-xproject
+-xproject
| +-main.cpp
+-xproject.xcodeproj
Let me describe it (not sure if its necessary). The base folder is myproject, everything inside it was created by xcode.
Instead, I would like have main.cpp outside, like the following:
myproject
+-main.cpp
+-xproject
+-xproject.xcodeproj
Is that possible? How can I get things this way?
Why I want that? Because different IDEs offer different benefits (and debugging in qtcreator might be less straightforward than in xcode, How to debug C++ project using Qt Creator?)
Actually xproject.xcodeproj is a folder which contains:
xproject/xproject.xcodeproj
├── project.pbxproj
├── project.xcworkspace
│   ├── contents.xcworkspacedata
│   ├── xcshareddata
│   │   └── IDEWorkspaceChecks.plist
│   └── xcuserdata
│   └── user.xcuserdatad
│   └── UserInterfaceState.xcuserstate
└── xcuserdata
└── user.xcuserdatad
└── xcschemes
└── xcschememanagement.plist
What I tried (looks like Eljay approach): Open project on xcode, remove xproject/main.cpp and then add myproject/main.cpp. Hit play button and it says build succedded. But also says:
Could not launch "xproject"
LLDB provided no error string.
When I click details I get:
Domain: IDEDebugSessionErrorDomain
Code: 3
Failure Reason: LLDB provided no error string.
User Info: {
DVTRadarComponentKey = 855031;
RawLLDBErrorMessage = "LLDB provided no error string.";
}
ln -s xproject/main.cpp main.cpp
Although I don't like this solution because the original file have to be inside xcode project.
I tried the oposite, but then xcode refuses to work.

Reason to add empty source file to a STATIC library?

I've seen this quite a lot in C++, that developers add an empty source file to the library in CMake. One example is here, with the empty source file found here.
The CMake file has this line:
# build the library
add_library(${PROJECT_NAME} STATIC src/dependency-tracker.cc)
This is only the case if there are no other source files in the src folder, so the library would be 'header only'. Why do they do this?
The directory structure i was referring to:
.
├── CMakeLists.txt
├── include
│   └── okvis
│   └── kinematics
│   ├── implementation
│   │   └── Transformation.hpp <- header only implementation
│   ├── operators.hpp
│   └── Transformation.hpp
├── src
│   └── dependency-tracker.cc <- empty source file
└── test
├── runTests.cpp
└── TestTransformation.cpp
The project specifies CMake 2.8.11 as a minimal requirement:
cmake_minimum_required(VERSION 2.8.11)
This version lacks for INTERFACE library type, which nowadays is a standard representation of a header-only library. (Support for INTERFACE libraries firstly appeared in CMake 3.0).
Without INTERFACE library available, a normal library with a single empty source file looks like a good alternative.
I don't know why dependency-tracker.cc name choosen for the empty source file. Probably, this name has some special meaning for the project's developers.

local socket = require("socket"), module 'socket' not found

Im using Lua with C++ in a project in Visual Studio 2015. I have used Luarocks to create socket/core.dll and mime/core.dll. I have added the core.dll to the debug folder where my C++ program executes. The error I get in lua is generated when "require("socket")" executes. The following error is what I get:
...s\Visual Studio 2015\Projects\RaceGame3\Debug\Client.lua:17: module
'socket' not found:
no field package.preload['socket']
no file 'C:\Users\Username\Documents\Visual Studio
2015\Projects\RaceGame3\Debug\lua\socket.lua'
no file 'C:\Users\Username\Documents\Visual Studio 2015\Projects\RaceGame3\Debug\lua\socket\init.lua'
no file 'C:\Users\Username\Documents\Visual Studio 2015\Projects\RaceGame3\Debug\socket.lua'
no file 'C:\Users\Username\Documents\Visual Studio 2015\Projects\RaceGame3\Debug\socket\init.lua'
no file 'C:\Users\Username\Documents\Visual Studio 2015\Projects\RaceGame3\Debug\..\share\lua\5.3\socket.lua'
no file 'C:\Users\Username\Documents\Visual Studio 2015\Projects\RaceGame3\Debug\..\share\lua\5.3\socket\init.lua'
no file '.\socket.lua'
no file '.\socket\init.lua'
no file 'C:\Users\Username\Documents\Visual Studio 2015\Projects\RaceGame3\Debug\socket.dll'
no file 'C:\Users\Username\Documents\Visual Studio 2015\Projects\RaceGame3\Debug\..\lib\lua\5.3\socket.dll'
no file 'C:\Users\Username\Documents\Visual Studio 2015\Projects\RaceGame3\Debug\loadall.dll'
no file '.\socket.dll'
So to sum up: How do I correctly link the core.dll or other luasocket files to my current Lua instance while running the C++ project?
I've solved a similar issue by changing the require to:
require("socket.core")
That only works, of course, if you have the core.dll inside a folder named socket that can be found locally or in your PATH / package.cpath, etc..
You could also rename core.dll to socket.dll (and place it in a searchable folder).
The problem, as far as I know, is: the required name and the actual dll name simply doesn't match.
edit: To play safe, I've put the lua modules and the dll together, locally, like this:
socket
├── core.dll
├── ltn12.lua
├── mime.lua
├── mime-1.0.3.dll
├── socket
│   ├── ftp.lua
│   ├── headers.lua
│   ├── http.lua
│   ├── smtp.lua
│   ├── tp.lua
│   └── url.lua
└── socket.lua
You were in a very similar situation to me. In my case, I required socket.http in sample.lua,
require("socket.http")
content, status, header = socket.http.request("http://website.com/aaa.php")
and have met the following error message:
...\MyProject\Release\sample.lua:1: module 'socket.http' not found:
no field package.preload['socket.http']
no file '.\socket\http.lua'
(...)
I've addressed this issue by putting some necessary lua scripts and dll files in the path where a sample executable is located.
Release
├── socket
│ ├── ftp.lua
│ ├── http.lua
│ ├── smtp.lua
│ ├── tp.lua
│ └── url.lua
├── mime
│ └── core.dll
├── ltn12.lua
├── mime.lua
├── socket.dll <--- renamed from $(LUA_PATH)\clibs\socket\core.dll
├── socket.lua
├── lua5.1.dll
├── sample.exe
└── sample.lua
The cpp code is as follows:
#pragma comment(lib, "lua5.1.lib")
#include <lua.hpp>
void main() {
lua_State *L = luaL_newstate();
luaL_openlibs(L);
luaL_dofile(L, "sample.lua");
lua_close(L);
}