I'm opening a dynamic library with a call to dlopen():
void *handle = dlopen("mylib.so", RTLD_LAZY | RTLD_GLOBAL);
if (!handle)
printf("%s", dlerror());
When this is called for a library which has an undefined symbol, the returned handle is NULL and I get the following printed in TTY:
libmylib.so: undefined symbol: < the_symbol_name >
This is fine. But when I call this same code for the same library name for the second time, the returned handle is NOT NULL, and I get a crash when dereferencing it.
From the docs:
If dlopen() fails for any reason, it returns NULL.
So why isn't NULL returned the second time?
Related
I am trying to cross-compile CPython 3.8 using Android NDK toolchains with enabled _socket module but unfortunately compilation failes at:
../Modules/socketmodule.c:6739:5: error: invalid use of undefined type 'struct if_nameindex'
for (i = 0; ni[i].if_index != 0 && i < INT_MAX; i++) {
^
../Modules/socketmodule.c:6739:19: error: dereferencing pointer to incomplete type
for (i = 0; ni[i].if_index != 0 && i < INT_MAX; i++) {
^
../Modules/socketmodule.c:6753:17: error: invalid use of undefined type 'struct if_nameindex'
ni[i].if_index, PyUnicode_DecodeFSDefault, ni[i].if_name);
^
../Modules/socketmodule.c:6753:19: error: dereferencing pointer to incomplete type
ni[i].if_index, PyUnicode_DecodeFSDefault, ni[i].if_name);
^
../Modules/socketmodule.c:6753:17: error: invalid use of undefined type 'struct if_nameindex'
ni[i].if_index, PyUnicode_DecodeFSDefault, ni[i].if_name);
^
../Modules/socketmodule.c:6753:62: error: dereferencing pointer to incomplete type
ni[i].if_index, PyUnicode_DecodeFSDefault, ni[i].if_name);
^
Whithout _socket module the whole cross-compilation works well, there are no errors.
Problem solved using the latest r23b version of Android NDK.
I am using Ubuntu Linux and Android (android-ndk-r21d). When I am compiling my code with ndk-build, I am getting compilation error for posix_spawnp function call. I have included the header <spawn.h> for this function. I am unable to figure what compilation and Link flags I should use for this function in my Android.mk file. Is this function supported on Android-ndk ?
alc#alc:~/src/ForkBench(master)$ ndk-build NDK_PROJECT_PATH=./
[arm64-v8a] Compile : forkBench <= forkBench.c
jni/../forkBench.c:61:12: error: implicit declaration of function 'posix_spawnp' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
status = posix_spawnp(&pid, TRUEAPP, NULL, NULL, launch_argv, NULL);
^
jni/../forkBench.c:90:12: error: implicit declaration of function 'posix_spawnp' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
status = posix_spawnp(&pid, TRUEAPP, NULL, NULL, launch_argv, NULL);
^
2 errors generated.
make: *** [/home/alc/android-ndk-r21d-linux-x86_64/android-ndk-r21d/build/core/build-binary.mk:476: obj/local/arm64-v8a/objs/forkBench/__/forkBench.o] Error 1
I got a doozie here. In Electron's main process, I require in the function below to setup event handlers with ipcMain. This keeps the main.js file a little more streamlined. All went swimmingly until I wrote some validation code to ensure that the user passes in an object. I use typeof all the time for this purpose, and never have I had an issue. But in Electron I am getting:
A JavaScript error occurred in the main process - TypeError: Cannot
assign to read only property 'exports' of object '# '
The code:
const {ipcMain} = require('electron');
function ipcSetup() {
ipcMain.on('123', function(event, arg) {
// this blows chunks...
if(arg && typeof arg === 'object') {
console.log(`All good....`);
}
// and if you comment that out, this use of "typeof" does the same thing
console.log(typeof arg);
// and to eliminate 'arg' as the issue...
let a = 1;
console.log(typeof a); // expect 'number', get Exception
});
}
module.exports = ipcSetup;
I didn't know if Electron is using Object.defineProperty to make arg read only, but typeof is not making an assignment here anyway, and I eliminated arg so this error makes no sense. Environment is Electron 1.8.4 on Node 8.2.1 using electron-vue
If you're importing that module in another module that uses ES6 import/export syntax, using typeof apparently causes this. I think this is because webpack doesn't support mixing the two syntaxes. But it is quite funny that it would work fine if you didn't use the typeof operator...
OK, I admit it, this is a unique case. When we build our application we are using make, so I've included my tests in a test folder under src. Then at the same level as our release folder we have created a unit-test folder that includes all of our source files and our test source files.
But my IDE is CLion, which uses CMake. In my CMakeLists.txt file, I have included:
enable_testing()
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
add_executable(TestProject ${SOURCE_FILES})
target_link_libraries(TestProject ${GTEST_BOTH_LIBRARIES})
I am creating my first Test Fixture. Here is the code:
#include "OPProperties.h"
#include "gtest/gtest.h"
namespace {
// The fixture for testing class OPPropertiesTestTest.
class OPPropertiesTestTest : public ::testing::Test {
protected:
// You can remove any or all of the following functions if its body
// is empty.
OPPropertiesTestTest() {
// You can do set-up work for each test here.
}
virtual ~OPPropertiesTestTest() {
// You can do clean-up work that doesn't throw exceptions here.
}
// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following methods:
virtual void SetUp() {
// Code here will be called immediately after the constructor (right
// before each test).
}
virtual void TearDown() {
// Code here will be called immediately after each test (right
// before the destructor).
}
// Objects declared here can be used by all tests in the test case for OPPropertiesTestTest.
};
TEST_F(OPPropertiesTestTest, ThisTestWillFail) {
EXPECT_EQ(0, 2);
}
} // namespace
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Here is an image capture:
Notice the syntax checker errors in my TEST_F function. When I started to type TEST_F code completion is trying to find a Boost Test Function.
Can someone tell me what else I need to add to the CMakeLists.txt file or what I am not doing that GTest functions are not being recognized?
As πάντα ῥεῖ pointed out, I hadn't actually tried to build the code. When I did I first received a linker error for pthread, so we added the following line the the CMakeLists.txt file:
target_link_libraries(OnePrint pthread)
Then I tried again to build and received these errors:
/home/user/gtest-1.7.0/lib/.libs/libgtest.so: undefined reference to `pthread_key_create'
/home/user/gtest-1.7.0/lib/.libs/libgtest.so: undefined reference to `pthread_getspecific'
/home/user/gtest-1.7.0/lib/.libs/libgtest.so: undefined reference to `pthread_key_delete'
/home/user/gtest-1.7.0/lib/.libs/libgtest.so: undefined reference to `pthread_setspecific'
collect2: error: ld returned 1 exit status
So, I ran a search on these errors and found this question.
The answer that worked for me was here.
I'm making my first attempt at using the text.js plugin (v2.0.12) for require.js (v2.1.15). I've had require working well up to this point, however, when I attempt to resolve a text dependency, I get two errors. The first error is Unable to get property 'normalize' of undefined or null reference [require.js, Line: 955] then, after the allotted time, I'll get a timeout error for the html file I'm attempting to load. The focus of this cry for help is the former error.
One curious observation I've noticed is that if I resolve the text module without declaring a file, there is no error. However, when I add the file path e.g. text!path/file, the error is triggered.
Additionally, I noticed that the load timeout error references the text module with _unnormalized2 appended. Not sure if that's to be expected but I thought is odd. Any help would be greatly appreciated!
Here's the block of code which errors:
//If current map is not normalized, wait for that
//normalized name to load instead of continuing.
if (this.map.unnormalized) {
//Normalize the ID if the plugin allows it.
if (plugin.normalize) { // error occurs here (line 955)
name = plugin.normalize(name, function (name) {
return normalize(name, parentName, true);
}) || '';
}
// ...
}
Ok, it turns out to have been a self-sabotage! I was creating a shortcut definition for the text module for which I left out the factory method. So, instead of
define('text', ['Scripts/text'], function(text) { return text; });
I had:
define('text', ['Scripts/text']);
Nothing to do with text.js whatsoever.