I want to use libwebsockets in a foreign libuv loop.
My code (inspired from this simple example) compiles and links correctly, but at execution, on webpage request, the browser never receives a response from the server.
I build both libwebsockets (v3.1.0) and libuv (v1.25.0) from the sources in my cmake. I use the following command line:
cmake -DLWS_WITH_LIBUV=1 .. && make
And the cmake ouput mentions the correct value for the option:
LWS_WITH_LIBEV = OFF
LWS_WITH_LIBUV = 1
LWS_WITH_LIBEVENT = OFF
Grepping for the option in the build directory gives the following (which looks ok too):
CMakeCache.txt:483:LWS_WITH_LIBUV:BOOL=ON
extern/libwebsockets/include/libwebsockets/lws-service.h:185:#ifdef LWS_WITH_LIBUV
extern/libwebsockets/include/libwebsockets/lws-service.h:209:#endif /* LWS_WITH_LIBUV */
extern/libwebsockets/include/libwebsockets.h:157:#ifdef LWS_WITH_LIBUV
extern/libwebsockets/include/libwebsockets.h:165:#endif /* LWS_WITH_LIBUV */
extern/libwebsockets/include/lws_config.h:72:#define LWS_WITH_LIBUV
extern/libwebsockets/lws_config.h:72:#define LWS_WITH_LIBUV
However, with the following code (the closest I have from a minimal (not) working example) no message is displayed.
#include <uv.h>
int main()
{
#ifdef LWS_WITH_LIBUV
std::cout<<"With libuv"<<std::endl;
#endif
}
I've looked here and here and I do not know what to do next.
Turns out I had libwebsockets installed on my system and was linking against this system library, not compiled with libuv support.
Related
I am testing openssl under macos.
First, I installed openssl through brew install openssl, and the installation location is: /usr/local/Cellar/openssl#3/3.0.5/.
Then I created a simple macos command line project, and then wrote some very simple code to reference the openssl encryption and decryption library.
In order to pass the compilation, I added the include path of openssl in the header file search path.
Then I added a reference to libcrypto.a in the Build Phase options. From what I understand, this library should be a static library, then when linking, the linker should copy all its code into my process without adding references to other dynamic libraries. But the strange thing is that when I try to debug and run the project, the process actually tries to load a dynamic library libcrypto.3.dylib that I have never referenced, and the loading fails because the dynamic library has no signature.
dyld[4481]: Library not loaded: '/usr/local/opt/openssl#3/lib/libcrypto.3.dylib'
Referenced from: '/Users/dongbo/Library/Developer/Xcode/DerivedData/TestOpenSSL-abmortoxmqaalbcuirkuraizktsa/Build/Products/Debug/TestOpenSSL'
Reason: tried: '/Users/dongbo/Library/Developer/Xcode/DerivedData/TestOpenSSL-abmortoxmqaalbcuirkuraizktsa/Build/Products/Debug/libcrypto.3.dylib' (no such file), '/usr/lib/system/introspection/libcrypto.3.dylib' (no such file), '/usr/local/opt/openssl#3/lib/libcrypto.3.dylib' (code signature in <BF9EFA44-EE24-3AF6-B0D4-3DFC6E454288> '/usr/local/Cellar/openssl#3/3.0.5/lib/libcrypto.3.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.), '/usr/local/lib/libcrypto.3.dylib' (no such file), '/usr/lib/libcrypto.3.dylib' (no such file), '/Users/dongbo/Library/Developer/Xcode/DerivedData/TestOpenSSL-abmortoxmqaalbcuirkuraizktsa/Build/Products/Debug/libcrypto.3.dylib' (no such file), '/usr/lib/system/introspection/libcrypto.3.dylib' (no such file), '/usr/local/Cellar/openssl#3/3.0.5/lib/libcrypto.3.dylib' (code signature in <BF9EFA44-EE24-3AF6-B0D4-3DFC6E454288> '/usr/local/Cellar/openssl#3/3.0.5/lib/libcrypto.3.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.), '/usr/local/lib/libcrypto.3.dylib' (no such file), '/usr/lib/libcrypto.3.dylib' (no such file)
Program ended with exit code: 9
I'm getting this error while testing on an intel-architecture imac, but magically, I'm doing the same on an m1 with no issues, except my m1 pro has sip turned off.
I don't know if everyone knows the reason for this?
all test codes:
#import <Foundation/Foundation.h>
#include <string>
#include <openssl/rsa.h>
#include <openssl/pem.h>
const std::string pk = std::string("-----BEGIN PUBLIC KEY-----\n") +
"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDTlCZFucurE+QNupniPUXz5RwN\n" +
"dhRAplB+jd51U4NTcpDl4AL3LppKdRxEyt4FlvLiE66tmonEJTc4BcaRurxxXOuY\n" +
"+0IS4l28FynYT/yDpdoiop0Jf2NCa8V5nCBISKp1Lgvz7AbHBw+3KNCF1UdrOeRs\n" +
"r/GBOSXosmTzPMRUNwIDAQAB\n" +
"-----END PUBLIC KEY-----";
std::string decrypt_string(const void* data, size_t length)
{
BIO* bio = BIO_new_mem_buf(pk.c_str(), (int)pk.size());
RSA* rsa = NULL;
PEM_read_bio_RSA_PUBKEY(bio, &rsa, 0, 0);
char buf[1024] = {0};
int ret = RSA_public_decrypt(0x80, (const unsigned char*)data, (unsigned char*)buf, rsa, RSA_PKCS1_PADDING);
if(ret == -1)
{
BIO_free(bio);
printf("decrypt error:%d\n", ret);
return "Error";
}
BIO_free(bio);
std::string str = buf;
return buf;
}
int main(int argc, const char * argv[]) {
#autoreleasepool {
// insert code here...
NSLog(#"Hello, World!");
}
return 0;
}
First, openssl is in fact considered deprecated and the corresponding headers were removed from macOS SDK 10.11 (the replacement is Secure Transport API).
Second, when linking a libName.a archive from Xcode settings, Xcode in fact transform this into -lName flag when linking. It means Xcode doesn't refer to any specific path you provided, but instead looks for appropriate libraries in the default search-libs paths (in addition to the provided ones).
If for any reason you still need the library Apple recommends just build it locally and embed the archive in the project bundle:
Add the library archive to the project:
Provide path to the system headers (it can be just headers paths, but i prefer system headers for 3-rd party libraries to avoid redundant warnings):
Add the archive to Embed Frameworks but not Link Binary build phases (we avoid using Link Binary step because if the library exists in the outdated macOS SDK, Xcode mail fail to disambiguate it with the embedded version):
Add linker flag to the Build Settings which points to your archive in the project directory (don't worry that such a directory doesn't exist for a product, the Embed Frameworks phase will resolve this path into the correct one):
At this point the library should link without errors.
I'm making a proc_macro crate where I have 2 examples in the directory examples/.
When I run cargo test, the 2 examples are compiled but one of the examples is failing on purpose and it prevents the test from running. I want to make an example that fails to compile to show the user how it works.
According to the doc this behavior is intended:
They must compile as executables (with a main() function) and load in the library by using extern crate <library-name>. They are compiled when you run your tests to protect them from bitrotting.
This is fine but how can I disable the compilation for my failing example?
I found it!
You can disable the automatic discovery of examples by adding autoexamples = false to [package]
Then you can enumerate all the examples yourself in the following way:
[package]
...
autoexamples = false
[[example]]
name = "basic"
path = "examples/basic.rs"
I was trying use build wxWidgets-3.1.3 with MinGW-W64 on a x64 windows machine.
I followed this thread, which lead me to download and building. So I installed it and some youtube videos said I need to build it now. So navigate to the installed folder and gave this command :
mingw32-make -f makefile.gcc BUILD=release SHARED=1 MONOLITHIC=1 UNICODE=1.
It took almost half an hour and now it's giving me error saying :
collect2.exe: error: ld returned 1 exit status
makefile.gcc:5329: recipe for target '..\..\lib\gcc_dll\wxmsw313u_gcc_custom.dll' failed
mingw32-make: *** [..\..\lib\gcc_dll\wxmsw313u_gcc_custom.dll] Error 1
Here is the full log file :
https://pastebin.com/zxeHhF6K
MinGW configuration :
Version : 8.1.0
Architecture : x86_64
Threads : posix
Exceptions : seh
Build version : 0
How can I solve this? I'm using CLion, is there any other short or easy way?
The relevant error is
..\..\lib\gcc_dll/libwxexpat.a(wxexpat_xmlparse.o):xmlparse.c:(.text+0x337d): undefined reference to `_imp__rand_s'
and it's very strange because MinGW-w64 8.1 is definitely supposed to have rand_s(). Are you sure you're using the right compiler? I.e. what does g++ -v give you if you run it from the same command prompt?
My only hypothesis is that it's some different (and much older) compiler and the solution would be to just use the right one instead.
Also, the next time you could use -j4 option with make if you have at least 4 logical CPUs in your machine (and chances are you do nowadays), to significantly speed up the build.
Looking back in my notes I once had an issue with missing rand_s() when building glib2 on a certain MinGW build.
I was able to fix it then by adding this at the top of the C file that called this function:
#include <time.h>
#include <stdlib.h>
int rand_s (unsigned int* r)
{
static int srand_called = 0;
if (!srand_called) {
srand(time(0));
srand_called++;
}
if (r)
*r = rand();
return 0;
}
In your case that would be in xmlparse.c.
I'm currently trying to learn how to use the FreeType2 library for drawing fonts with OpenGL. However, when I start the program it immediately crashes with the following error: "(Can't correctly start the application (0xc000007b))"
Commenting the FT_Init_FreeType removes the error and my game starts just fine. I'm wondering if it's my code or has something to do with loading the dll file.
My code:
#include "SpaceGame.h"
#include <ft2build.h>
#include FT_FREETYPE_H
//Freetype test
FT_Library library;
Game::Game(int Width, int Height)
{
//Freetype
FT_Error error = FT_Init_FreeType(&library);
if(error)
{
cout << "Error occured during FT initialisation" << endl;
}
And my current use of the FreeType2 files.
Inside my bin folder (where debug .exe is located) is: freetype6.dll, libfreetype.dll.a, libfreetype-6.dll.
In Code::Blocks, I've linked to the lib and include folder of the FreeType 2.3.5.1 version.
And included a compiler flag: -lfreetype
My program starts perfectly fine if I comment out the FT_Init function which means the includes, and library files should be fine.
For people who might stumble upon the same problem and can't find it out. I'll post my solution:
It seemed the error code ussualy comes up with loading .dll's. I used process explorer to check if my program was actually loading the correct .dll but it wasn't. I deleted my FreeType dll's and replaced them with a version compiled specifically for my version of windows to make sure I have the right dll's. Replacing the old one with the new one helped.
I had the same problem, turnes out that I had forgotten to copy over the zlib1.dll file.
I had the same "cant correctly start" error. It turned out my program was finding a zlib1.dll in something like c:\intel\wifi\bin, that DependencyWalker flagged as AMD64 (my PC is Win7 64, but my app is 32 bits.) It was fixed when I copied freeType's zlib1.dll to SysWOW64. Tough nut to crack!
Is there a way to know if the program is running in the development environment? I'm using Flurry Analytics and want to pass it a different app id, so the data doesn't get dirty with my tests during development.
What I'd like is something like this:
Boolean isDevEnv = .... (is this a test in the simulator or device,
OR is it a real user that downloaded the
app through the app store?)
if (isDevEnv)
[FlurryAnalytics startSession:#"firstAppId"];
else
[FlurryAnalytics startSession:#"secondAppId"];
To be clear, this is not what I'm after, because I test using a real device as well as the simulator.
In the build settings you'll have to set flags, depending on the building env.
Then, use #ifdef and #define to set the appid.
#ifdef DEBUG
# define APPID ...
#else
# define APPID ...
#endif
In your build settings, define a new flag for the App Store release version. Then use #ifdef to determine at compile time which appid to use.
if you don't want to use DEBUG flag and DEBUG environment, create a new build configuration (duplicate Release configuration) and in the build settings Preprocessor Macros add a FlurryAnalytics flag. In your code check if(FlurryAnalytics). Create a new scheme in XCode that creates ipa using this new release build configuration.
Well, it seems this is done by default by Xode, in the Project's Build Settings, under Apple LLVM compiler 3.1 - Preprocessing (this is in Xcode 4.3.2, for future reference), a setting called DEBUG is populated with the value 1.
So, I didn't really have to do anything, just this in the code (in my case in the AppDelegate's didFinishLaunchingWithOptions method):
[FlurryAnalytics startSession:DEBUG ? #"firstAppId" : #"secondAppId"];